I wish to focus to the top portion of aspx page on changing the view of multiview under button click...I have set update panel but triggers are given for some and hence post back occurs...Provide a solution at the earliest...

Dani AI

Generated

Short summary and practical fix for the UpdatePanel + MultiView case (refs: , , ).

The key point: a page-level “maintain scroll” solution handles full postbacks but not partial (async) postbacks from UpdatePanel. When the MultiView is switched inside an UpdatePanel the page isn’t reloaded, so the browser doesn’t jump to the top automatically. The simplest, reliable approach is to emit client script that runs after the async postback and either scrolls the window or sets focus on a top element.

Example (server-side, in the button click that changes the view):

// switch view
MultiView1.ActiveViewIndex = 1;

// scroll to top after the async postback
ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(),
    "scrollTop", "window.scrollTo(0,0);", true);

Or to set keyboard focus to a control in the new view:

MultiView1.ActiveViewIndex = 1;
string script = "var el = document.getElementById('" + txtFirstField.ClientID + "'); if(el) el.focus();";
ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "focusTop", script, true);

Troubleshooting tips:

  • Make sure the button that triggers the view change is inside the UpdatePanel or registered as an AsyncPostBackTrigger (PostBackTrigger will do a full postback).
  • Use ScriptManager.RegisterStartupScript (not ClientScript) for async postbacks.
  • If attaching AJAX endRequest handlers, avoid adding duplicates on every partial postback.
  • If a smooth scroll is desired and jQuery is available, replace window.scrollTo(0,0) with $('html,body').animate({scrollTop:0},200);.

These patterns cover the common causes when the page stays scrolled down after switching MultiView inside an UpdatePanel.

Recommended Answers

All 2 Replies

Member Avatar for Member #949455

focus to the top portion of aspx page on changing the view of multiview

You really need to post some codes or show at least a image what you are having issue. It seems like you just post a thread without really explaining what issue you are having.

Are you starting to used ASP.net software?

It's seem like you are very trouble placing the code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.