how to get onfocus OR onenter Textbox asp.net
-
Hi, i wanna to call the bellow function while the Textbox1 got focus (when user click on Textbox1 OR when user press tab and textbox1 got focus):
`Untitled Page function Open() { var Return; var myObject = new Object(); myObject.TextBox1 = document.getElementById("txtFirstName").value; if (window.showModalDialog) { Return = window.showModalDialog("childform.aspx", myObject, "dialogWidth:670px;dialogHeight:600px;") document.getElementById("txtFirstName").value = Return.firstname; } }`
-
Hi, i wanna to call the bellow function while the Textbox1 got focus (when user click on Textbox1 OR when user press tab and textbox1 got focus):
`Untitled Page function Open() { var Return; var myObject = new Object(); myObject.TextBox1 = document.getElementById("txtFirstName").value; if (window.showModalDialog) { Return = window.showModalDialog("childform.aspx", myObject, "dialogWidth:670px;dialogHeight:600px;") document.getElementById("txtFirstName").value = Return.firstname; } }`
Write this in your code behind file:
myTextBox.Attributes.Add("onfocus","javascript: Open();");
This will add the onfocus client side event to your textbox.
Sandeep Mewara Microsoft ASP.NET MVP [My latest Article]: Server side Delimiters in ASP.NET[^]
-
Hi, i wanna to call the bellow function while the Textbox1 got focus (when user click on Textbox1 OR when user press tab and textbox1 got focus):
`Untitled Page function Open() { var Return; var myObject = new Object(); myObject.TextBox1 = document.getElementById("txtFirstName").value; if (window.showModalDialog) { Return = window.showModalDialog("childform.aspx", myObject, "dialogWidth:670px;dialogHeight:600px;") document.getElementById("txtFirstName").value = Return.firstname; } }`
In order to call the JavaScript function, Just use the Following: protected void Page_Load(object sender, EventArgs e) { TextBox1.Attributes.Add("onfocus", "Open()"); } This will bind the "onfocus" event of TextBox1 to the javascript function "Open()"
-
In order to call the JavaScript function, Just use the Following: protected void Page_Load(object sender, EventArgs e) { TextBox1.Attributes.Add("onfocus", "Open()"); } This will bind the "onfocus" event of TextBox1 to the javascript function "Open()"
But unlike others i believe you should handle it from your client and not ASP.net. You should implement it as follow:
document.getElementById("<%= TextBox1.ClientID %>").onfocus=function(){Open();}