Click to See Complete Forum and Search --> : setting focus to a dynamically created web control
ctmas_m
July 13th, 2005, 12:51 PM
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..
hoffmandirt
July 13th, 2005, 02:20 PM
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.
// 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);
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.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.