|
-
July 13th, 2005, 12:51 PM
#1
setting focus to a dynamically created web control
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..
-
July 13th, 2005, 02:20 PM
#2
Re: setting focus to a dynamically created web control
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.
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);
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|