Solved

Setting focus after postback

Posted on 2008-10-13
11
376 Views
Last Modified: 2013-12-17
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#
0
Comment
Question by:introlux
  • 6
  • 5
11 Comments
 
LVL 7

Expert Comment

by:ajolly
ID: 22702469
do you want to focus some specific control?
0
 

Author Comment

by:introlux
ID: 22702496
i.e. the gridview, or where the button was clicked, or even a text box.

These type of items
0
 
LVL 7

Expert Comment

by:ajolly
ID: 22702505
use TextBox1.Focus();
0
 

Author Comment

by:introlux
ID: 22702516
What would you do with a gridview?
0
 
LVL 7

Expert Comment

by:ajolly
ID: 22702536
GridView1.Focus();
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:introlux
ID: 22702560
the gridview does not work. keeps browser at top screen
0
 
LVL 7

Expert Comment

by:ajolly
ID: 22702565
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
 
LVL 7

Accepted Solution

by:
ajolly earned 500 total points
ID: 22702582
okay ... understood.

for that you need to maintain your scroll position on postback
@Page maintainScrollPositionOnPostBack="true"
0
 

Author Comment

by:introlux
ID: 22702579
Error:

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

Set_Focus();
0
 
LVL 7

Expert Comment

by:ajolly
ID: 22702607
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
 

Author Closing Comment

by:introlux
ID: 31406266
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Loop not working 29 48
Replace &lt; with < 14 57
C# HTTP GET method sample code 3 42
Executing SSIS with a Stored Procedure Permissions 12 32
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now