Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
hi guys,

i have input type text box in a aspx page. i want to check on button click whether the text is "text1" then on button click other page will be open.


please help me as sson as possible.
Posted
Updated 4-Oct-12 16:15pm
v2
Comments
Ambesha 5-Oct-12 6:40am    
you required to do in JavaScript or c#?

Try this.

In you .aspx page

XML
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />


In your .aspx.cs page

C#
protected void Button1_Click(object sender, EventArgs e)
   {
       if (TextBox1.Text == "text1")
       {
           Response.Redirect(url);//here url is which page you need to open
       }
       else
       {
           TextBox1.Focus();
       }
   }
 
Share this answer
 
Search the net for client side validation. You would want to write a js function which does what you need to do on the POST request of Form

XML
<FORM action="http://somesite.com/page.htm onsubmit="validateForm()"  method="post">
 
Share this answer
 
On button click write bellow cod

Assume the textbox id is txtbox1

   if(txtbox1.Text=="text1")
{
 
  Response.Redirect("abc.aspx");
 //Server.Transfer("xyz.aspx");

}
 
Share this answer
 
hi,


XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="head1" runat="server">
    <title>Button.OnClientClick Example</title>
</head>
<body>
  <form id="form1" runat="server">

    <h3>Button.OnClientClick Example</h3>


      <h4>Click to navigate to Microsoft.com:</h4>

      <asp:button id="Button1"
       usesubmitbehavior="true"
       text="Open Web site"
       onclientclick="Navigate()"
       runat="server" />

       <p></p>
      <asp:label id="Label1"
        runat="server">
      </asp:label>

    </form>

    <script type="text/javascript">
      function Navigate()
      {
        javascript:window.open("http://www.microsoft.com");
      }

    </script>
</body>
</html>
 
Share this answer
 
Comments
Rockstar_ 5-Oct-12 1:14am    
In javascript code you can write the code for testing weather the textbox contains your text or not....then you can navigate...
try this:
.aspx.cs page:
C#
protected void Button1_Click(object sender, EventArgs e)
       {
           if (TextBox1.Text.ToUpper().Equals("TEXT1"))
           {
               Response.Redirect(url);// URL for Next Page
           }
           else
           {
               TextBox1.Text = "";
               TextBox1.Focus();
           }
       }

.aspx page:
HTML
<![CDATA[<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="CoreClinica.Web.WebForm1" %>]]>
 
Share this answer
 
Try this

XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="head1" runat="server">
    <title>Button.OnClientClick Example</title>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
        function Validate() {
            if ($("#TextBox1").val() == "text1") {

                window.location = "../javascriptredirect.aspx"///for example
            }
            else {
                $("#TextBox1").val('');
                $("#TextBox1").focus();
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Validate" OnClientClick="Validate();" />
    </form>
</body>
</html>
C#

 
Share this answer
 
v3
try this:
.aspx.cs page:
C#
protected void Button1_Click(object sender, EventArgs e)
       {
           if (TextBox1.Text.ToUpper().Equals("TEXT1"))
           {
               Response.Redirect(url);// URL for Next Page
           }
           else
           {
               TextBox1.Text = "";
               TextBox1.Focus();
           }
       }

.aspx page:
ASP.NET
<body>
    <form id="form1" runat="server">
    <div>
        <asp:textbox id="TextBox1" runat="server" xmlns:asp="#unknown"></asp:textbox>
        <asp:button id="Button1" runat="server" text="Button" onclick="Button1_Click" xmlns:asp="#unknown" />
    </div>
    
</body>
 
Share this answer
 
Comments
prashant patil 4987 5-Oct-12 1:51am    
is this solution not working/???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900