Re: Using bookmarks within a page.
ASP.NET
Thread Starter: mike55
Started:
Replies: 2

Ireland .NET Developer Alliance :: Forums » Technologies » ASP.NET » Re: Using bookmarks within a page.
« Previous Thread Next Thread »
   05 Oct 2005, 1:46
mike55 is not online. Last active: 21/12/2005 09:28:10 mike55

Top 10 Posts
Joined on 01-20-2005
Posts 40
Using bookmarks within a page.
Hi all

I am trying to set-up my page that when the user clicks the next button, validation will be performed. If the validation fails, the user will be redirected to where the validation summary appears in the page, could be at the top, bottom, or in the middle.

I have created a number of anchors around my page and I am able to redirect to them without loosing any of my information in the event of an error.  The problem that I am having is that a new instance of the page is being created each time that I do the redirect to the anchor location even though I am using javascipt to handle the redirection.

Here is my code:
                                    

Private Sub registerAnchorScript( ByVal strAnchorID As String )

   Dim Script As String

   Script &= "

   Script &= "var hashValue='#" & strAnchorID & "';" & vbCrLf

   Script &= "if(location.hash!=hashValue)" & vbCrLf

   Script &= "location.hash=hashValue;" & vbCrLf

   Script &= "" & vbCrLf

   If ( Not Page.IsStartupScriptRegistered("BookMarkScript")) Then

      Page.RegisterStartupScript("BookMarkScript", Script)

   End If

End Sub




 
I simple pass the name of the anchor that I want to redirect to into this method.

Appreciate any suggestions.

Mike55.
  
   07 Oct 2005, 10:05
FelixByrne is not online. Last active: 22/11/2005 09:38:00 FelixByrne

Top 25 Posts
Joined on 05-09-2005
Posts 4
Re: Using bookmarks within a page.
Hi

Try the following rather than using the validation controls

add a web forms panel (ie a server  side div) for each validation summary

and a click event to your button (or form if you want everything validated)
cmdSubmit.attributes.add("onclick",'return ValidateMe();')

in the Validation routine do your checking and if you get any errors
populate your divs .innnerHTML then you can scroll to that div by using  something  like
pageScroll(0,200) ;  (see below)
and finally return false (this will cancel the  post back)

If all is ok return true

function pageScroll(posX,posY )
{
    // horizontal and vertical scroll increments
    window.scrollBy(posX,posY);
}

examples:
http://www.mediacollege.com/internet/javascript/page/scroll.html

If you dont know the position of the div / anchor on the page (if its all realative)
you could use something like the following

http://www.mattkruse.com/javascript/anchorposition/source.html

however you would still need to validate on server
just in case somebody tries to get around your validation

Hope this Helps

Felix

 
    
   17 Oct 2005, 2:08
mike55 is not online. Last active: 21/12/2005 09:28:10 mike55

Top 10 Posts
Joined on 01-20-2005
Posts 40
Re: Using bookmarks within a page.
Thanks lad,

Took some of your suggestion and applied it to my project.  What I did is I kept how I was validating the data as it was, but when the validation failed, I called the following method which relocated to the required location.

'Scroll the user to the validation summary.

Private Sub ScrollPage(byVal x as int16, byval y as int16)

Dim script As String

script &= "

script &= "window.scrollTo(x, y);" & vbCrLf

script &= "" & vbCrLf

' Firstly confirm that there is no scripting conflict in terms of id.

If Not Page.IsStartupScriptRegistered("scroll") Then

' Register the script.

Page.RegisterStartupScript("scroll", script)

End If

End Sub
  
  Page 1 of 1 (3 items)
Ireland .NET Developer Alliance :: Forums » Technologies » ASP.NET » Re: Using bookmarks within a page.

Powered by Community Server :: Forums