How do I scroll to a bookmark in a sub?

Jackpanel

Freshman
Joined
Feb 23, 2004
Messages
35
I've put together a page that lists items in a data grid. I've set it up so that when a user clicks the item description, it loads up a panel below the list with the details for that item. I've got this part working, but would like to make the page scroll down to the top of the details section when it reloads. I've inserted a bookmark (a name="Details") at the beginning of the Details section, but can't figure out how to make the page jump to this bookmark once it reloads.

Here's the code I'm using:

Code:
<ItemTemplate>
  <asp:LinkButton id="ItemDetailsLink" 
onCommand="ItemDetailsLink_Command"
CommandName="ItemID"
CommandArgument='<%# DataBinder.Eval(Container, 
"DataItem.ID").ToString %>' runat="server">
  <%# Container.DataItem("Description") %>
  </asp:LinkButton>
</ItemTemplate>

Code:
    sub ItemDetailsLink_Command(sender as Object, e as CommandEventArgs)
        pnlItemDetails.visible="true"
        ShowDetails(e.CommandArgument)
    End Sub


    Sub ShowDetails(ItemID as String)
        dim dbconn,sql,dbcomm,dbread,i

        ' Show the Item details
        dbconn=New OleDbConnection(Application("ConnectionString"))
        dbconn.Open()
        sql="SELECT * FROM Orders
WHERE Opportunity = '" & Httpcontext.Current.Request.Querystring("ID") & "' 
AND ID =  " & ItemID & " ORDER BY OrderID"
        dbcomm=New OleDbCommand(sql,dbconn)
        dbread=dbcomm.ExecuteReader()

        ItemDetails.DataSource = dbread
        ItemDetails.DataBind()

        dbread.Close()
        dbconn.Close()

    End Sub
 
Last edited:
I don't do this with a bookmark. I do it with a class that sets focus. The code for the class is:
Code:
    Public Class SetFocus

        Public Sub SetFocus(ByVal controlToFocus As Control, ByVal callingPage As Page)
            Dim scriptFunction As String
            Dim scriptClientId As String

            scriptClientId = controlToFocus.ClientID

            scriptFunction = "<script language='javascript'>"
            scriptFunction += "document.getElementById('" & scriptClientId & "').focus();"
            scriptFunction += "</script>"

            callingPage.RegisterStartupScript("focus", scriptFunction.ToString())
        End Sub

    End Class

Then I end the routine that causes the postback with:
Code:
Dim objSF as new SetFocus

objSF.SetFocus(PanelWithDetails, Me)

HTH

Eva
 
I've created a SetFocus.vb class, but I'm having problems trying to compile it. The error message I'm getting is "Type 'Control' is not defined" and "Type 'Page' is not defined". I'm assuming its either because I'm not including the right Imports or haven't set up my compiler properly.

Code:
Imports System

Namespace OrderManager

    Public Class SetFocus
        Public Sub SetFocus(ByVal controlToFocus As Control, ByVal callingPage As Page)
            Dim scriptFunction As String
            Dim scriptClientId As String

            scriptClientId = controlToFocus.ClientID

            scriptFunction = "<script language='javascript'>"
            scriptFunction += "document.getElementById('" & scriptClientId & "').focus();"
            scriptFunction += "</script>"

            callingPage.RegisterStartupScript("focus", scriptFunction.ToString())
        End Sub
    End Class
End Namespace

The compile command:

vbc /t:library SetFocus.vb
 
I don't compile this on its own. I just include it as part of my Common.vb in whatever ASP.Net project I am using it in and then reference it from there. Are you compiling only this?
 
Yeah, I haven't had a need for a common functions VB file in my project yet, so was just trying to compile that sub on its own.
 
ah... ok. Now you have a need:-) This won't work compiled on its own exactly as you have seen. It needs the project to have references to all the system.web stuff.

Sorry, I should have made that clearer when I first sent you the code. Go to Project and "Add Class". This will give you a .vb file. Call that whatever you like. As I said before, I like to call it "Common". Then put this inside it.

Let me know if I am still missing something I should be telling you.
 
Back
Top