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

  • Home
  • SEARCH
  • 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 7812833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:38:33+00:00 2026-06-02T04:38:33+00:00

I have an asp.net button: <asp:Button ID=MainContent_ibSave runat=server Text=Save /> </td> I need to

  • 0

I have an asp.net button:

 <asp:Button ID="MainContent_ibSave" runat="server" Text="Save" />
                </td>

I need to keep the runat=server because I have to process some code behind when its clicked.
But in the jquery I have this:

 $("#MainContent_ibSave").click(function () {
            if ($('#MainContent_txtShipToName').val().length == 0) {
                $('#hErrorsExist').val("1");
                $('#error').show();
            }
            else {
                $('#hErrorsExist').val("0");
                $('#error').hide();
            }

Basically what I’m doing here is just checking if any text has been entered in #MainContent_txtShipToName. I want to throw an error message if nothing is entered. To do so I thought I’d add a hidden field:

<input id="hErrorsExist" type="hidden" />

To maintain the state of whether an error exists on the page or not.
This is so if an error exists on the form I can set the value to 1 otherwise I set it to 0.

After I click this button it sets the value to 1 shows the #error (which is just a div), but then the div disappears. Its as if the postback has reset the value of hErrorsExist…

I even added a check in my jquery:

  if ($('#hErrorsExist').val() == "0" || $('#hErrorsExist').val().length == 0) {
            alert("about to hide");
            $('#error').hide();
            alert($('#hErrorsExist').val());
        }
        else {
            $('#error').show();
            alert($('#hErrorsExist').val());
        }

This is the first thing in my document ready function. I dont know how to handle this so that the div #error stays up even after the button post back. If I do enter a value and it validates it should set hErrorsExist to 0 and hide the div #error and keep the div hidden after post back.

Here’s the full jquery:

 $(document).ready(function () {
        /*hide message container on top*/
        //alert($('#hErrorsExist').val().length);
        if ($('#hErrorsExist').val() == "0" || $('#hErrorsExist').val().length == 0) {
            alert("about to hide");
            $('#error').hide();
            alert($('#hErrorsExist').val());
        }
        else {
            $('#error').show();
            alert($('#hErrorsExist').val());
        }

          $("#MainContent_ibSave").click(function () {
            if ($('#MainContent_txtShipToName').val().length == 0) {
                $('#hErrorsExist').val("1");
                alert("Setting to 1");
                alert($('#hErrorsExist').val());
                $('#error').show();
            }
            else {
                $('#hErrorsExist').val("0");
                alert("Setting to 0");
                alert($('#hErrorsExist').val());
                $('#error').hide();
            }
        });
          }); 
  • 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-06-02T04:38:36+00:00Added an answer on June 2, 2026 at 4:38 am

    Have you tried this?

    $("#<%= MainContent_ibSave.ClientID %>").click(function (arg) {
       arg.preventDefault();
       if ($('#MainContent_txtShipToName').val().length == 0) {
           $('#hErrorsExist').val("1");
           $('#error').show();
       }
       else {
           $('#hErrorsExist').val("0");
           $('#error').hide();
       }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have this asp.net button: <asp:Button ID=Button_Save Width=150px OnClick=Button_Save_Click runat=server Text=Save /> In
I have this ASP.net component: <asp:Button ID=Button4 runat=server Text=Submit Entry CssClass=eventSubmitButton OnClick=SubmitData/> and I'd
I have an asp.net button control on the page. <asp:Button ID=btnFinishReceiving runat=server Text=Finished Receiving
I have an ASP.Net-Button which, when clicked, executes client side and server side code.
I have ASP.Net code generating my button's HTML for me using divs to get
I have an asp.net button, that when clicked calls a code behind function. The
I have some javascript on an asp.net page code behind, but whenever the page
Wondering if there is a way to have multicolor text for ASP.NET Button Text.
I need some help with jQuery and stopping an asp.net button postback. If you
I have an asp.net button on a web page. The OnClientClick code disables the

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.