Button Question. Can u help me?

  • Thread starter Miguel Dias Moura
  • Start date
M

Miguel Dias Moura

Hello,

i have a form in an ASP.net / VB with 2 buttons:

<code>
<form action="" class="tableForm" runat="server">
<asp:Button ID="Ybt" runat="server" OnClick="Go" Text="Yes" />
<asp:Button ID="Nbt" runat="server" OnClick="Go" Text="No" />
</form>
</code>


and then i have this VB script:

<code>
<script runat="server">
Sub goToPage(sender As Object, e As System.EventArgs)
Response.Redirect("pageYes.aspx")
End Sub
</script>
</code>

What i want is to redirect to "pageYes.aspx" if button "Yes" is pressed and
to "pageNo.aspx" if button "No" is pressed.

In this moment it redirects allways to the same page. Can u help me out?

Thank You,
Miguel
 
G

Greg

Miguel said:
Hello,

i have a form in an ASP.net / VB with 2 buttons:

<code>
<form action="" class="tableForm" runat="server">
<asp:Button ID="Ybt" runat="server" OnClick="Go" Text="Yes" />
<asp:Button ID="Nbt" runat="server" OnClick="Go" Text="No" />
</form>
</code>


and then i have this VB script:

<code>
<script runat="server">
Sub goToPage(sender As Object, e As System.EventArgs)
Response.Redirect("pageYes.aspx")
End Sub
</script>
</code>

What i want is to redirect to "pageYes.aspx" if button "Yes" is pressed and
to "pageNo.aspx" if button "No" is pressed.

In this moment it redirects allways to the same page. Can u help me out?

Thank You,
Miguel

This isn't of much help, but while playing with your code I noticed that
even though the sender is read properly, it doesn't work when comparing:

<script runat="server">
Sub goToPage(sender As Object, e As System.EventArgs)
If (sender.ID = "Ytb") Then
Response.Redirect("pageYes.aspx")
Else
Response.Write(sender.ID)
End If
End Sub
</script>

You'll notice that even though it writes Ytb when the Yes button is
clicked (instead of redirecting), in the If statement, (sender.ID =
"Ytb") is always False for some reason.

What about having two subs (this works)?

<form action="" class="tableForm" runat="server">
<asp:Button ID="Ybt" runat="server" OnClick="goToPage" Text="Yes" />
<asp:Button ID="Nbt" runat="server" OnClick="goToPage2" Text="No" />
</form>

<script runat="server">
Sub goToPage(sender As Object, e As System.EventArgs)
Response.Redirect("pageYes.aspx")
End Sub

Sub goToPage2(sender As Object, e As System.EventArgs)
Response.Redirect("pageNo.aspx")
End Sub
</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top