introlux
asked on
Setting focus after postback
Hi,
I have looked on the net for examples of what I am trying to do, but needing help. Basically After a postback (note this could be from buttons to lstbox item changed)
Once this is done, I would like to set the browser to focus on a certain area. Does not need to have an active curson in a text box for example.
Any help to get this sorted, will be appreciated.
Regards,
intorlux
ASP.Net C#
I have looked on the net for examples of what I am trying to do, but needing help. Basically After a postback (note this could be from buttons to lstbox item changed)
Once this is done, I would like to set the browser to focus on a certain area. Does not need to have an active curson in a text box for example.
Any help to get this sorted, will be appreciated.
Regards,
intorlux
ASP.Net C#
do you want to focus some specific control?
ASKER
i.e. the gridview, or where the button was clicked, or even a text box.
These type of items
These type of items
use TextBox1.Focus();
ASKER
What would you do with a gridview?
GridView1.Focus();
ASKER
the gridview does not work. keeps browser at top screen
or alternatively you can use:
Write following function in your codebehind and for every control call this function which needs to be focused.
private void Set_Focus(string controlname)
{
string strScript;
strScript = "<script language=javascript> document.all('" + controlname + "').focus() </script>";
RegisterStartupScript("foc us", strScript);
}
Source: http://forums.devarticles.com/net-development-43/setting-textbox-focus-in-c-56162.html
Write following function in your codebehind and for every control call this function which needs to be focused.
private void Set_Focus(string controlname)
{
string strScript;
strScript = "<script language=javascript> document.all('" + controlname + "').focus() </script>";
RegisterStartupScript("foc
}
Source: http://forums.devarticles.com/net-development-43/setting-textbox-focus-in-c-56162.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Error:
CS1501: No overload for method 'Set_Focus' takes '0' arguments
Set_Focus();
CS1501: No overload for method 'Set_Focus' takes '0' arguments
Set_Focus();
avoid javascript method for now.
Implement the scroll position method.
for information:
To make the javascript work, you need to pass the client id of the control that you want to set focus as an argument.
Implement the scroll position method.
for information:
To make the javascript work, you need to pass the client id of the control that you want to set focus as an argument.
ASKER
Thank you! This does more or less what I need. As I can use the other method such as txtText1.focus(); if i need a text box curser in there. Thanks again for your help!