Reputation: 115
if (Request["__EVENTARGUMENT"] != null && Request["__EVENTARGUMENT"] == "txt2OnClick")
{
txt2_Click();
}
txt2.Attributes.Add("onclick", this.Page.ClientScript.GetPostBackEventReference(txt2, "txt2OnClick")); //within page load
private void txt2_Click()
{
ImageMap1.ImageUrl = "guide/2.jpg";
}
This is a perfect piece of code to have a click event on textbox, with asp.net (C#).
But the only problem is, we cant type when we apply this code to a textbox. So what I did was set the focus txt2.Focus();
then I can type, but the textbox is not getting validated (I have added a regular expression validator) . Any help? Even to have a better onClick event for a textbox than this?
Upvotes: 0
Views: 4114
Reputation: 3850
I don't see any point in having click event for text box.. Remove your 'perfect piece of code' and txt2 if not required..If you have added regular expression validator
correctly, it will take care of validation..
EDIT:
For changing some text or showing some image, you don't need to post back to server..
You can either use javascript Focus event or jquery to do that..
In the link you provided, all those photos and texts are placed on div
s and are already loaded on browser and when textbox gets focus, those div styles are just toggled between none
and block
..
Something like this(jsFiddle)..
Upvotes: 2