Link to home
Start Free TrialLog in
Avatar of rgrimm
rgrimm

asked on

Server.Transfer and "Error executing child request for..." error.

In my web page I have an HTML anchor tag that acts as a bookmark:

<A name="bookmark"></A>

When a command button on the page is clicked, I do a postback. If certain conditions exist, then I want to jump to the above bookmark. I use a line of code that looks like this:

Server.Transfer("#bookmark")

This generates the following error on the Server.Transfer line:

"Error executing child request for #bookmark."

How do I make my code jump to this bookmark?
Avatar of DotNetLover_Baan
DotNetLover_Baan

I am using Javascript to do that. Here is an example..

    Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
        Dim stscript As String = "<script language=JavaScript>self.scrollTo(0,812);</script>"
        If (Not Page.IsStartupScriptRegistered("clientScript")) Then
            Page.RegisterStartupScript("clientScript", stscript)
        End If
    End Sub

-Baan
Avatar of rgrimm

ASKER

The JavaScript scrollTo method takes two arguments: xPosition and yPosition. It moves you to a specified x,y coordinate (origin is the top-left corner of the window) on the page. I need to go to a specific anchor tag.
use response.redirect("Page.aspx?#bookmark")

zulu
That will cause a postback...  I was trying to avoid a post back.
Avatar of rgrimm

ASKER

I tried using both of the following:

Server.Transfer("Page.aspx?#Bookmark")
Response.Redirect("Page.aspx?#Bookmark")

Both cause a fresh, blank page to reload, which I don't want. I need a postback that maintains the page state.
Avatar of rgrimm

ASKER

Here is the solution. It works great. Many thanks to Keem. See the link at the bottom for the entire discussion thread.

In VB.NET Create a method something like this...

Private Sub MoveToAnchor(ByVal anchorName As String)
  'Returns page to the given anchor
  Page.RegisterStartupScript("MoveToAnchor", "<script language=JavaScript>document.location.hash = '" & anchorName & "'</script>")
End Sub

Then if you have an anchor

<a name="Bookmark"></a>

In the VB.NET code just change your code to

If repSearchResults.Items.Count > 0 Then 'If repeater control has records, show panel, hide buttons
  pnlDuplicate.Visible = True
  cmdUpdate.Visible = False
  cmdCancel.Visible = False
  MoveToAnchor("Bookmark")
End If

( i'm guessing here that you are posting back to the same page, other wise you'd do do a Server.Transfer to the required page and then the call the MoveToAnchor )

********************************************************
http://www.gotdotnet.com/Community/MessageBoard/Thread.aspx?id=263244&Page=1#264260 
 
ASKER CERTIFIED SOLUTION
Avatar of ee_ai_construct
ee_ai_construct
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial