?
Solved

Setting focus after postback

Posted on 2008-10-13
11
Medium Priority
?
395 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month17 days, 6 hours left to enroll

864 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