?
Solved

Setting focus after postback

Posted on 2008-10-13
11
Medium Priority
?
388 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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
 

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 2000 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

719 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