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 106769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:38:56+00:00 2026-05-11T01:38:56+00:00

I am validating a zip code using Javascript that is generated server-side, and injected

  • 0

I am validating a zip code using Javascript that is generated server-side, and injected when a LinkButton is clicked. Then, I retrieve the return value by calling a server-side function when the page loads.

This works nicely, but the problem is that the ViewState is completely lost after PostBack. Below is the code, starting with the page_load event, the button click event, and then the callback called from the page_load event.

Is there a way I can somehow save the ViewState, maybe easily in a session variable? Or is there a workaround I can use?

// In Page_Load if (Request.Form['__EVENTTARGET'] == 'CallFunction') {     GetValidateZipCodeScriptReturnValue(Boolean.Parse(Request.Form['__EVENTARGUMENT'].ToString())); }  // OnClick for LinkButton private bool ValidateZipCode(string zip) {     StringBuilder script = new StringBuilder();     script.Append('<script language='javascript' type='text/javascript'>');     script.Append(@'var regex = /^\d{5}$|^\d{5}-\d{4}$/;');     script.Append('__doPostBack('CallFunction', regex.test(' + zip + '));');     script.Append('</script>');      Type t = GetType();      if (!ClientScript.IsClientScriptBlockRegistered(t, 'ValidateZipCodeScript')) {         ClientScript.RegisterClientScriptBlock(t, 'ValidateZipCodeScript', script.ToString());     }      return false; }  // Method called on PostBack to get the return value of the javascript private void GetValidateZipCodeScriptReturnValue(bool valid) {     m_ZipCode = uxZip.Text;      if (valid) {         Response.Redirect(string.Format('~/checkout/overview.aspx?pc={0}&zc={1}',         ProductCode, ZipCode));     }     else {         Alert.Show('The entered zip code is invalid. Please ensure the zip code is a valid zip code.');         SetupPostBackViewState();         ScrollToZipCode();     } } 
  • 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. 2026-05-11T01:38:57+00:00Added an answer on May 11, 2026 at 1:38 am

    Why not just use the OnClick event of the LinkButton? Or, better yet, look into the CustomValidator control, since it looks like all you’re trying to do is validate a zip code and that’s exactly what a CustomValidator can do (you’ll need to look at the ClientValidationFunction, which is where you want to put your regex test).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 121k
  • Answers 121k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This looks like a good article that might help. http://www.c-sharpcorner.com/uploadfile/mahesh/user-control-in-wpf/… May 12, 2026 at 12:28 am
  • Editorial Team
    Editorial Team added an answer In some respects I think this is a good idea,… May 12, 2026 at 12:28 am
  • Editorial Team
    Editorial Team added an answer This should do it, assuming that your method has an… May 12, 2026 at 12:28 am

Related Questions

Yup, basically, I am building a web form that need to provide different required
I made this small location class so that I can better handle address information
I am attempting to programmatically add a test project to a solution. However when
I know this question might sound a little cheesy but this is the first

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.