0

In my register page I have a checkbox (chkAgree) next to the terms of agreement. The register (btnRegister) button is disabled until chkAgree.Checked = True. Since the registration section is toward the bottom of the page I want to redirect the user to an anchor tag during the event. I can't seem to accomplish this without one of the two objects in question losing their status. I tried creating a Session for each object and then calling them on the page load event with no luck. I am obviously doing it wrong, but could someone please point me in the right direction? btnRegister's default status is set to Enabled=False. Here are the two methods I am using

CheckedChanged:

Protected Sub chkAgree_CheckedChanged(sender As Object, e As EventArgs) Handles chkAgree.CheckedChanged
        Session("Agree") = chkAgree.Checked
        Response.Redirect("~/ExteriorStudentTestimonials.aspx#register", False)
    End Sub

And Page_Load:

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        If Session("Agree") = True Then
        btnRegister.Enabled = True
        chkAgree.Checked = True
    Else
        btnRegister.Enabled = False
        chkAgree.Checked = False
    End If
    End Sub

I have tried several different combinations of If statements but cannot figure it out without taking Response.Redirect("~/ExteriorStudentTestimonials.aspx#register", False) out.

NOSDUH
  • 111
  • 2
  • 12

2 Answers2

1

This might be related to the fact that you're reloading the page. You might want to take a look at the following question for some ideas of how to jump to an anchor without a full redirect: Programmatically scroll to an Anchor Tag

On a different note, jumping to an anchor when the user clicks a check box doesn't sound like a very good user experience. You might consider making your form shorter.

Community
  • 1
  • 1
Ilya Kogan
  • 21,995
  • 15
  • 85
  • 141
  • Thanks for the guidance. The problem is not with the length of the registration form, it's with the page. I have some content above the registration form so that the user has to scroll down in order to fill it out so I would rather have the page reload at the point of the registration form instead of having to scroll back down to complete the form. None of the examples from the link you posted have examples in VB. How would I script this in my code behind? @IlyaKogan – NOSDUH Nov 24 '15 at 05:37
  • Have you tried using just '#register' instead of the full path? – Ilya Kogan Nov 24 '15 at 05:48
  • `Response.Redirect("#register", False)`? That is not part of the directory. – NOSDUH Nov 24 '15 at 05:58
  • Okay, I see that you can't redirect to an anchor from the code-behind. I guess you'll need to use Javascript for that. – Ilya Kogan Nov 24 '15 at 06:11
0

Got it using this method similar to the ones described in the link you provided

Page.ClientScript.RegisterStartupScript(Page.GetType(),
                                        "navigate",
                                        "document.getElementById('register').scrollIntoView();",
                                        True)
NOSDUH
  • 111
  • 2
  • 12