|
What does your custom control look like? What does it do? How do you want to use the mouse events with your custom control? Basically, you can simply attach the mouse events to the Attribute collection of a child control of the custom control, if you are developing a composite control. If you create a rendered control, you can manage to do that in the overriden Render method. You can see the MSDN[^] for more information.
|
|
|
|
|
Well the control doesn't look like anything yet. It's just a new WebControlLibrary, i have set the backcolor so i can see it in the webpage, what i would like is when i hover the mouse over the control the event is triggered.
|
|
|
|
|
Piovra_ wrote: It's just a new WebControlLibrary, i have set the backcolor so i can see it in the webpage, what i would like is when i hover the mouse over the control the event is triggered.
Do you mean it's just a default control added to the project when you create a new web control library? When you hover the mouse over the control, you want the event to be triggered, so do you mean the onmouseover event or a custom event defined in the control. If it is simply the onmouseover event, you can add the onmouseover="alert();" to the control declaration on the web page.
|
|
|
|
|
Why does the repeater always change the name attributes of my checkboxes???? What the crap? how do I stop this? It keeps making them unique whent they should be identical..
/\ |_ E X E GG
|
|
|
|
|
Alex,
In the ASP.NET, any control should always be uniquely identified, so by default the id of the control within the scope of a naming container contains the id of its container. In the case of the repeater, the id of the checkboxes contains the id of the RepeaterItem, and the ASP.NET automatically does that for you. If you want this thing not to happen to the checkboxes, you may consider using the html checkbox input element which is not marked with the runat="server" .
|
|
|
|
|
oh the runat is doing it, thanks.
/\ |_ E X E GG
|
|
|
|
|
Actually, I'm kinda confused. So, I'll just keep my checkbox as runat=server.
But I'm confused on how I can access the checkbox from my code behind file....
Any tips?
/\ |_ E X E GG
|
|
|
|
|
eggie5 wrote: So, I'll just keep my checkbox as runat=server.
Yes, leave the checkbox marked with the runat="server".
eggie5 wrote: But I'm confused on how I can access the checkbox from my code behind file....
The sample code below shows you a way to access the checkbox in code-behind:
foreach (RepeaterItem item in Repeater1.Items)
{
CheckBox chkBox = item.FindControl("chkBox") as CheckBox;
if (chkBox != null)
{
....
}
} Depending which control you are using, you can choose the line with the CheckBox or the HtmlInputCheckBox control. In addition to the FindControl method, you can also access the checkbox control using the Controls collection.
|
|
|
|
|
I notice you only use "chkBox" for the checkbox ID, was this just for the example? I'm going to have to build the id dynamically right?
/\ |_ E X E GG
|
|
|
|
|
You name the checkbox as chkBox , or whatever you like, and you can use it later with the FindControl method. Also, you should bind data to the value attribute of the checkbox instead of the id of the control.
|
|
|
|
|
it seems as though the Items collection is all null...
/\ |_ E X E GG
|
|
|
|
|
foreach (RepeaterItem item in RepeaterCurrentAbstracts.Items)
do you have any idea why all my items would be null?
/\ |_ E X E GG
|
|
|
|
|
When/where do you run this code? It's before or after the datasource is bound to the control ( or the control hierarchy is built)? Btw, below is a quick example:
<%@ Page Language="C#" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Hashtable datasource = new Hashtable();
datasource.Add("key1", "value1");
datasource.Add("key2", "value2");
datasource.Add("key3", "value3");
datasource.Add("key4", "value4");
datasource.Add("key5", "value5");
Repeater1.DataSource = datasource;
Repeater1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (RepeaterItem item in Repeater1.Items)
{
CheckBox chkBox = item.FindControl("chkBox") as CheckBox;
if (chkBox != null && chkBox.Checked)
Response.Write("Selected value: " + chkBox.Attributes["value"] + "<br>");
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:CheckBox runat="server" ID="chkBox"
Text='<%# DataBinder.Eval(Container.DataItem, "Value") %>'
Value='<%# DataBinder.Eval(Container.DataItem, "Key") %>' />
<br />
</ItemTemplate>
</asp:Repeater>
<br />
<asp:Button ID="Button1" runat="server" Text="Push Me" On_Click="Button1_Click" />
</div>
</form>
</body>
</html>
|
|
|
|
|
HMMM... I don't know what the deal is but the debugger said the Items were null, but apparently it is working... Kinda...
I have a quick question on state. So I am on my webpage and check a checkbox and then click a button which runs a method in my code behind (so it posts back). I should have access to that checked using the FindControl code above right? Or is the state lost between the postback? Do I have to save the checkbox state somehow and then re set them?
/\ |_ E X E GG
|
|
|
|
|
eggie5 wrote: So I am on my webpage and check a checkbox and then click a button which runs a method in my code behind (so it posts back). I should have access to that checked using the FindControl code above right?
Yes.
eggie5 wrote: Or is the state lost between the postback?
No.
eggie5 wrote: Do I have to save the checkbox state somehow and then re set them?
No. The checkbox control knows how to save its checked status. In fact, the checkbox control updates its checked property at the server side based on it's postback data. If the checkbox is checked, its value is submitted to the server, and the control can gets the value when the post data is loaded (in the LoadPostData method). If the checkbox is not checked, data is not sent to the server, and based on this postback data, the control knows how to set the Checked property accordingly.
|
|
|
|
|
Hi all,
how to assign value to input file type tag.
i.e
i want to assign value to the control. when i give
file.value="india.gif"
it shows a error..
how to solve it. Pls help mee.
thanks
Paul
|
|
|
|
|
Paul,
The value property of the input file[^] element is read-only and does not have the default value, so you cannot set the default value for it.
|
|
|
|
|
Hi Paul,
The value of HTMLInputFile is not settable due to the security reasons. The value property of this control is readonly.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Hi,
I want to update the datagrid control, present in the parent page, from the child page without the page getting fully refreshed. Is there some way with which i can update the datagrid control without full page refresh?
Ashu
|
|
|
|
|
Hi,
You can use frames for that purpose.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Thanks Apurva...but i heard about something called 'scriptcallback'. this technique helps to update a single control on the page without full page reload. I have used 'scriptcallback' but only for html controls and not for asp.net server controls. Any idea?
Ashu
|
|
|
|
|
Hi Ashuu,
Actually i don't have much idea on using scriptcallback for server side controls. But you can also tryout xmlhttp.
http://www.codeproject.com/jscript/refreshpartweb.asp
http://www.15seconds.com/Issue/000612.htm
hope this will be helpful to you.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Thank Apurva,
this link do talk about script callback but nothing is given about asp.net datagrid...its been long time searching for it...anyways.. thanks dear.
Ashu
|
|
|
|
|
Hi
I am using C# and ASP.Net through Visual Studio to develope a Web Application.
I have a DataList that I databind to a DataTable called categoryTable. The categoryTable was loaded from the database and contains a CategoryIndex column and a CategoryName column.
DataList_Categories.DataSource = categoryTable;
DataList_Categories.DataBind();
The DataList contains a LinkButton in each row on which I display the CategoryName:
<ItemTemplate>
<asp:LinkButton CommandName="select" Text='<%# DataBinder.Eval (Container, "DataItem.CategoryName")%>' runat="server">
</asp:LinkButton>
</ItemTemplate>
When I select an item in the DataList I want to get the CategoryIndex from the selected row and load the appropriate products to display them in another DataList. How do I get that information (CategoryIndex) out of the DataListItem?
private void DataList_Categories_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
if (e.CommandName == "select")
{
int index = e.Item.ItemIndex;
DataListItem item = DataList_Categories.Items[index];
}
}
Thanks
Kobus
|
|
|
|
|
Hi Kobus,
Pass that as command argument from the html side and then use it in the code behind side like e.commandargument.
Best Regards,
Apurva Kaushal
|
|
|
|