views:

90

answers:

2

Hi,

I have a user control(error control) in a master page. by default the user control is hidden(visible false)

on click of a submit button i am showing the error control.Now on post back I want to bring focus to this control.I am writing the java script in register Startup script as following:

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Scroll", "window.scrollTo(0, 0)", true);

on postback page goes up shows this control and then comes back to its previous scroll position.

A: 

Have you set MaintainScrollPositionOnPostback to true in the page directive at the top of your page/master page or in the <pages> element of your web.config?

You could also look at using the Focus method of the control in your postback handler

Edit to clarify:

If any of these are set to true then it's very likely that they will override your startup script to send the page back to the top of the page - have you tried setting it to false in either the Page directive, or on the Page object in the same code that displays the error control?

Zhaph - Ben Duguid
I have tried that also it dosent work
SaveMe
Hi I am calling followin method on button click event still no use.. as u can see I have tried script manager.setfocus also but no respite.public void SetFocus() { Page.MaintainScrollPositionOnPostBack = false; ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Scroll", "window.scrollTo(0, 0)", true); // ScriptManager1.SetFocus(ErrorControl1.FocusControl); }
SaveMe
A: 

hi All,

Finally I have solved this issue. following is the way i am doing it...

i have added a text box of width Zero% in the same where my user control(error control is placed)

now whenever an error occurs I call following method.

public void SetFocus() { ScriptManager3.SetFocus(txtFocus.ClientID); }

although error control is not focused in reality this clever work around helps me achieve my goal.

hope it is helpful for others

SaveMe