Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6586473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:47:42+00:00 2026-05-25T16:47:42+00:00

So, i have an aspx page which looks like this: <%@ Page Language=C# AutoEventWireup=true

  • 0

So, i have an aspx page which looks like this:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
</body>
</html>

I would like to know, how I can write JavaScript (e.g. jQuery) code that will call a function from my C# Code. Lets say this is my C# method:

protected void XXX(object sender, EventArgs e)
{
    Response.Redirect("pagewho?");
}

Thanks again, Alon. 🙂

EDIT:

This is the full code i am using the moment:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
  <script type="text/javascript">
      validateStuff = function () {
          var isValid = true;
          var txt = document.getElementById("TextBox1");

          if (txt) {
              if (txt.value.toLower() != "james") {
                  isValid = false;
              }
          }
          //perform validation and return true/false
          return isValid;
      }

  </script>
    <form id="form1" runat="server">
    <div>
    <asp:Button ID="Button1" runat="server" OnClientClick="return validateStuff();" OnClick="Button1_Click" />
        <br />
        <br />
        <asp:TextBox ID="TextBox1" runat="server" Height="25px" Width="135px"></asp:TextBox>
        <br />
        <br />
        <br />
    </div>
    </form>
</body>
</html>

but, no matter what i am wireting in the textbox, its return true. any help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:47:43+00:00Added an answer on May 25, 2026 at 4:47 pm

    You can use __doPostBack from the script, and use the RaisePostBackEvent method in the code behind to perform your server-side logic. If you’re looking to do a redirect, this would probably be the best way.

    EDIT

    If you’re looking to do some validation in JavaScript when a button is clicked, use OnClientClick to perform your JavaScript validation, and return true if the validation succeeds.

    <asp:Button ID="Button1" runat="server" OnClientClick="return validateStuff();" OnClick="Button1_Click" />
    

    Your JavaScript validation:

    validateStuff = function(){
        var isValid = true;
        var txt = document.getElementById("<%=TextBox1.ClientID%>");
        if (txt.value.toLower() != "james"){
           isValid = false;
        }        
        return isValid;
    }
    

    If the validateStuff function returns true, a postback will occur and you can handle your save/update logic in the button click event:

    protected void Button1_Click(object sender, EventArgs e)
    {
        //save some stuff to the database
    
        string txtValue = TextBox1.Text.Trim();
    }
    

    In JavaScript:

    redirectToAnotherPage = function(){
        __doPostBack("<%=SomeServerControl.ClientID%>", "someArgument");
    }
    

    In the code-behind:

    protected override void RaisePostBackEvent(IPostBackEventHandler source, string eventArgument)
    {
        //call the RaisePostBack event 
        base.RaisePostBackEvent(source, eventArgument);
    
        Response.Redirect("anotherpage.aspx");
    }
    

    If all you’re looking to do is bring the user to another page, you can also do this:

    redirectToAnotherPage = function(){
        window.location.href = "somepage.aspx";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WebParts.aspx page which looks like this - <%@ Page Language=C# AutoEventWireup=true
So I have a file called WebParts.aspx which looks like this - <%@ Page
I have Default.aspx page, which inherits from BasePage.cs, which inherits from System.Web.UI.Page. BasePage is
I have a code in VB that looks like this: 'Server.Transfer(txtUser.Text + _page.aspx) which
I have a URL which looks like this: http://www.website.co.uk/en-us/aboutus/thegroup/test.aspx I have a UL LI
I have a aspx page that looks something like this: <tr id=Row1> <td>Some label</td>
I have a panel on an aspx page which contains an UpdatePanel. This panel
In my aspx page I have a tr which is set visible=false by default.
I have a .aspx page which I want the browser to treat like a
I have the .aspx page which is already developed in VS 2008 with its

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.