Solved

Setting focus after postback

Posted on 2008-10-13
11
375 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

14 Experts available now in Live!

Get 1:1 Help Now