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#
introluxAsked:
Who is Participating?
 
ajollyConnect With a Mentor Commented:
okay ... understood.

for that you need to maintain your scroll position on postback
@Page maintainScrollPositionOnPostBack="true"
0
 
ajollyCommented:
do you want to focus some specific control?
0
 
introluxAuthor Commented:
i.e. the gridview, or where the button was clicked, or even a text box.

These type of items
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
ajollyCommented:
use TextBox1.Focus();
0
 
introluxAuthor Commented:
What would you do with a gridview?
0
 
ajollyCommented:
GridView1.Focus();
0
 
introluxAuthor Commented:
the gridview does not work. keeps browser at top screen
0
 
ajollyCommented:
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("focus", strScript);
}

Source: http://forums.devarticles.com/net-development-43/setting-textbox-focus-in-c-56162.html
0
 
introluxAuthor Commented:
Error:

CS1501: No overload for method 'Set_Focus' takes '0' arguments

Set_Focus();
0
 
ajollyCommented:
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.
0
 
introluxAuthor Commented:
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!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.