Hi all im still all very new to this area so apologies in advance for the poor explanation of the problem.
My app is written VS2005,C# & ASP. I am trying to get an onClick event working with a textbox, but as many of you will probably know that no such event exist with textboxes (which seems silly to me btw). Anyway after trawling thru the internet it appears what I need to do I use the attributes collection to add an “onClick” event to the text box
For example:
Now my understanding is that with this line I can then write a line in the aspx code to handle the onClick event.
Which then means I can write a method in the code behind (.cs) to handle txtDealtWith_onClick.
But when I step through the code, clicking on the textbox does nothing, it does not hit the code I have written. What have I done worong? Am I missing something? Do I still need javascript in the aspx?
Also I do not understand what the second part of the Add.Attributes statement is doing? i.e What does “txtclick” (in this instance) actually refer to?
Please help cus this is driving me mad!
Thanks in advance.
My app is written VS2005,C# & ASP. I am trying to get an onClick event working with a textbox, but as many of you will probably know that no such event exist with textboxes (which seems silly to me btw). Anyway after trawling thru the internet it appears what I need to do I use the attributes collection to add an “onClick” event to the text box
For example:
Code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.txtDealtWith.Attributes.Add("onClick", "txtclick");
…other code etc etc
}
}
Now my understanding is that with this line I can then write a line in the aspx code to handle the onClick event.
Code:
<asp:TextBox ID="txtDealtWith" runat="server" onClick="txtDealtWith_onClick" ToolTip="Dealt With Date" AutoPostBack="True"></asp:TextBox>
Which then means I can write a method in the code behind (.cs) to handle txtDealtWith_onClick.
Code:
protected void txtDealtWith_OnClick(object sender, EventArgs e)
{
}
But when I step through the code, clicking on the textbox does nothing, it does not hit the code I have written. What have I done worong? Am I missing something? Do I still need javascript in the aspx?
Also I do not understand what the second part of the Add.Attributes statement is doing? i.e What does “txtclick” (in this instance) actually refer to?
Code:
txtDealtWith.Attributes.Add("onClick", "txtclick");
Please help cus this is driving me mad!
Thanks in advance.