Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET GimmeCode
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 4-Oct-12 13:02pm
Edited 4-Oct-12 17:15pm
v2
Comments
Ambesha at 5-Oct-12 6:40am
   
you required to do in JavaScript or c#?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try this.
 
In you .aspx page
 
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
 
In your .aspx.cs page
 
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();
       }
   }
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
 
<FORM action="http://somesite.com/page.htm onsubmit="validateForm()"  method="post">
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

On button click write bellow cod
 
Assume the textbox id is txtbox1
 
   if(txtbox1.Text=="text1")
{
 
  Response.Redirect("abc.aspx");
 //Server.Transfer("xyz.aspx");

}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

hi,
 

<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>
  Permalink  
Comments
VijayChauhan123 at 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...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

try this:
.aspx.cs page:
 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:
<![CDATA[<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="CoreClinica.Web.WebForm1" %>]]>
 
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

Try this
 
<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>
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

try this:
.aspx.cs page:
 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:
 
<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>
 
  Permalink  
Comments
prashant patil 4987 at 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)



Advertise | Privacy | Mobile
Web02 | 2.8.150327.1 | Last Updated 5 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100