This is a migrated thread and some comments may be shown as answers.

go to anchor on selectedindex changing

2 Answers 59 Views
Grid
This is a migrated thread and some comments may be shown as answers.
golddog
Top achievements
Rank 1
golddog asked on 12 Sep 2008, 09:08 PM
We have in our master page a setup like this:

<a id="#SearchResults>
<asp:ContentPlaceHolder id="cphSearchResults" runat="server"/>

<a id="#Edit">
<asp:ContentPlaceHolder id="cphEdit" runat="server"/>

Then, in each page in our application, we put a radgrid in the search results place holder, and an edit control in the other.  When we click a row in the search results grid, we invoke a process to look up that item, populate the edit control, and make the edit control visible.

What I'm trying to accomplish is to position the browser at my #Edit anchor after this postback, so the user is positioned right at the edit control.

No luck so far, I've tried several variations of this:

protected void grdTemplate_SelectedIndexChanged(object sender, EventArgs e)
{
    
if (grdTemplate.SelectedValue is int)
    {
        
this.Presenter.Edit((int)grdTemplate.SelectedValue);
        ClientScript.RegisterStartupScript(
this.GetType(), "edit", "document.location = '#Edit';", true);
    }
}

Thinking that after postback, the location would be set to the #Edit anchor by javascript.  I don't see any evidence of this being in the page source after postback.

Anybody else have any ideas I might try?

2 Answers, 1 is accepted

Sort by
0
golddog
Top achievements
Rank 1
answered on 12 Sep 2008, 09:22 PM
In case anybody else is watching, I learned about System.Web.UI.ScriptManager.  That at least seems to invoke the script for me.

I'll have to do some fooling around with the URL to ensure I've gotten rid of any existing anchors, but a quick test seems like it might be the right track.
0
golddog
Top achievements
Rank 1
answered on 12 Sep 2008, 09:52 PM
Man, this is really close.  The browser does position at the #Edit tag while the page is loading, but when things are finished rendering, we pop back to where we were (or at least roughly, it seems) pre-click.

I did try setting the Page's MaintainScrollPositionOnPostback property false, thinking maybe that would let our tweak of the location stick, but no dice.

If anyone has any ideas, I'd sure appreciate it.  I'm out of ideas to try.
Tags
Grid
Asked by
golddog
Top achievements
Rank 1
Answers by
golddog
Top achievements
Rank 1
Share this question
or