Button Question.

  • Thread starter Thread starter Miguel Dias Moura
  • Start date 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
 
Hi Miguel,

You should be able to pass the clicked but as the Sender and then detect its
ID to determine which page to go to.

Here's one way, there are certainly many more:

<%@ Page Language="vb" AutoEventWireup="true"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>redir</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script language="vb" runat="server">
Sub goToPage(sender As Object, e As System.EventArgs)
dim btnSender as button
btnSender=Sender
Response.Redirect(iif(btnSender.ID="Ybt","pageYes.aspx","pageNo.aspx"))
End Sub
</script>
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form action="" class="tableForm" runat="server" ID="Form2">
<P>
<asp:Button ID="Ybt" runat="server" OnClick="goToPage" Text="Yes" />
<asp:Button ID="Nbt" runat="server" OnClick="goToPage" Text="No" /></P>
</form>
</body>
</HTML>

Does this help?

Ken
MVP [ASP.NET]
Toronto
 
Hi Ken,

this another sugestion i got. I think it's better:

<script runat="server">
Sub CommandBtn_Click(sender As Object, e As CommandEventArgs)
Select e.CommandName
Case "Yes"
Response.Redirect("Page Yes")
Case "No"
Response.Redirect("Page No")
End Select
End Sub
</script>

<asp:Button ID="Ybt" runat="server" Text="Yes" CommandName="Yes"
OnCommand="CommandBtn_Click"/>
<asp:Button ID="Nbt" runat="server" Text="No" CommandName="No"
OnCommand="CommandBtn_Click"/>

What do u think?

Cheers,
Miguel
Ken Cox said:
Hi Miguel,

You should be able to pass the clicked but as the Sender and then detect its
ID to determine which page to go to.

Here's one way, there are certainly many more:

<%@ Page Language="vb" AutoEventWireup="true"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>redir</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script language="vb" runat="server">
Sub goToPage(sender As Object, e As System.EventArgs)
dim btnSender as button
btnSender=Sender
Response.Redirect(iif(btnSender.ID="Ybt","pageYes.aspx","pageNo.aspx"))
End Sub
</script>
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form action="" class="tableForm" runat="server" ID="Form2">
<P>
<asp:Button ID="Ybt" runat="server" OnClick="goToPage" Text="Yes" />
<asp:Button ID="Nbt" runat="server" OnClick="goToPage" Text="No"
/> said:
</form>
</body>
</HTML>

Does this help?

Ken
MVP [ASP.NET]
Toronto


Miguel Dias Moura 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
 
Back
Top