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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:17:56+00:00 2026-06-18T11:17:56+00:00

I have added textbox on the page that Jquery to create a datepicker. The

  • 0

I have added textbox on the page that Jquery to create a datepicker. The problem is that, the textbox doesn’t hold the value after a postback. After researching, I found the following solution which works perfectly, i.e. the textbox keeps its value after a postback.

<th>
   <asp:CustomValidator ID="customStartDate" runat="server" 
    ErrorMessage="Start Date" Display = "None" ControlToValidate = "txtStartDate"
    ValidationGroup ="HireGroup" ClientValidationFunction ="StartDate_Validate"/>
    Start Date: 
</th>
<td>
   <asp:TextBox ID="txtStartDate" runat="server" Width = "140" ReadOnly = "true"
   TabIndex = "5" CssClass = "datepicker" ></asp:TextBox>
   <asp:HiddenField ID="hfDatePicker" runat="server"/>
</td>

And this is the Jquery code

//Set datePicker
function SetUpDatePicker() {
 var $allDatepickers = $('.datepicker');
 $.each($allDatepickers, function () {
    $(this).datepicker({
        showOn: "button",
        buttonImage: "Images/calendar.gif",
        buttonImageOnly: true,
        minDate: 1,
        altField: '[id*="hfDatePicker"]'
    });


    var $hfDatePicker = $('[id*="hfDatePicker"]');
    var val = $($hfDatePicker).attr('Value');
    $(this).val(val);

    var len = $($hfDatePicker).attr('Value').length;
    if (len > 0) {
        $(this).datepicker("setDate", new Date($($hfDatePicker).attr("Value")));
    }
  });
}

Now I have a different type of problem. I can’t use a RequiredFieldValidator for a HiddenField as I am getting an error “Hidden Field cannot be validate“.

I’m tryind a CustomValidator, but the problem is that this control does acts only when the ControlToValidate is not empty.

I’ve checked all the property for RequiredFieldValidator and don’t see something like ClientValidationFunction property.

Any suggestion on how to solve that problem?

  • 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-18T11:17:58+00:00Added an answer on June 18, 2026 at 11:17 am

    (Based on the comment by @Richard77, I will make this an actual answer.)

    You have a several options…

    Instead of using a <asp:Hidden>, use a normal <asp:TextBox> but hide it using style='display:none; attribute. This will allow you to use the <asp:RequiredFieldValidator> as per your needs.

    Another way to do it is using the <asp:CustomValidator> and add the ValidateEmptyText='true' attribute. This will force the validator to run the code even when the TextBox is empty.

    Update – after thinking about this, I would NOT recommend the following, because it’s not possible (that I can think of) to override the server-side version of the function, and therefore will leave you open to vulnerabilities. It’s fine to do if you’re purely using it for say visual reasons, and don’t need the actual data to be checked on the server – however, this is an unusual situation.

    A final option (but not one that I would necessarily recommend) is to override the function generated by ASP.NET. This would need to be placed on your page somewhere after the script link generated by ASP.NET, something like…

    function RequiredFieldValidatorEvaluateIsValid(val) {
      if(val.controltovalidate=="myValidatorId"){
        // your coding here
      } else {
        return (ValidatorTrim(ValidatorGetValue(val.controltovalidate)) != ValidatorTrim(val.initialvalue))
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've recently added the JQuery autocomplete plug in and have a textbox that autocompletes
I have text widgets that can be added on the page. A click should
I have created a control and added a TextBox inside that control, I am
What I have is button that should open another page only if textbox length
I have added a checker to ensure that all fields in a form have
i have added to my page an asp.net calendar control and i would like
I have added two update panels to my page. I'm trying to update the
On my C# asp.net webform I have a search page that has roughly 20
I have two form elements on my page that act as a smooth login
I am creating a web page, where I have an image that I want

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.