Hi,
I would like to know , how t set focus to a dynamically created control (text box) asp.net (C#)
When cliking a hyperlink control, text box will be created, since the focus is not set to the newly created control screen jumps up..
Printable View
Hi,
I would like to know , how t set focus to a dynamically created control (text box) asp.net (C#)
When cliking a hyperlink control, text box will be created, since the focus is not set to the newly created control screen jumps up..
I had to do the same thing.
Basically to get the page from jumping up I had to set the focus lower than my dynamically created control. So for my example, I have a TextBox that was created and then below that I had a save button.
on the postback, the focus is set to my button below the TextBox making it appear that the page never moved. Also if you just need focus to the TextBox because it just completely disappears replace btnSave with the ID of your textbox. Hope this helps.Code:// Create the focus script and set it to the save button to bring the
// user's view down far enough to see the result.
strSetFocus = "<script language=\"javascript\">\n";
strSetFocus += "document.getElementById('btnSave').focus();\n";
strSetFocus += "</script>";
// Register the startup script.
Page.RegisterStartupScript("SetFocus", strSetFocus);