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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:15:32+00:00 2026-05-20T10:15:32+00:00

I am developing one sharepoint webpart, in this i have 2 date time control,

  • 0

I am developing one sharepoint webpart, in this i have 2 date time control, one is for From date and another is for To date, And i wrote one javascript function to validate the date entered by the user. If the To date is less than the from Date, it will alerts. and i added this JS function to the button click as a attribute. But this function is not executing while i am clicking.

i am adding my code with this:

  void Registerscript()
    {
        string jc = @"<script> function DateMsg()
             {{ 

                var Fromdate = document.getElementById('{0}').value;
                var Todate = document.getElementById('{1}').value;

                 if(Fromdate != '' && Todate != '')
                {{             
                if(Date.parse(Fromdate) > Date.parse(Todate))
                  alert('From Date should be earlier than To Date.');
                }}

             }}</script> ";
        jc = string.Format(jc, dtFromdate.ClientID + "_dtFromdateDate", dtTodate.ClientID + "_dtTodateDate");
        this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", jc);
    }

I called this function in Createchildcontrol method of the webpart..

And i added this code on OnLoad event of the webpart

btnView.Attributes.Add("onclick", "DateMsg();");

Please help me for resoving this issue…

FYI: This btnView(Button control) is dynamically created at runtime..

Thanks in advance…

  • 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-20T10:15:33+00:00Added an answer on May 20, 2026 at 10:15 am

    I would go in different way, allowing easier debug.

    Have the function in the .aspx file:

    <script type="text/javascript">
    function DateMsg() {
        if (typeof _fromDateTextboxID != "undefined") {
            var oFromDateInput = document.getElementById(_fromDateTextboxID);
            var oToDateInput = document.getElementById(_toDateTextboxID);
    
            if (!oFromDateInput) {
                alert("element with ID of " + _fromDateTextboxID + " does not exist");
                return;
            }
    
            if (!oToDateInput) {
                alert("element with ID of " + _toDateTextboxID + " does not exist");
                return;
            }
    
            var strFromdate = oFromDateInput.value;
            var strTodate = oToDateInput.value;
            if(strFromdate.length == 0 || strTodate.length == 0) {
                alert("one or more values empty");
                return;
            }
    
            var dtFromDate = Date.parse(strFromdate);
            var dtToDate = Date.parse(Todate);
            if(dtFromDate > dtToDate) {
                alert('From Date should be earlier than To Date.');
            }
    
        }
        else {
            alert("ID not initialized");
        }
    }
    </script>
    

    And output only the ID from the code behind:

    string jc = string.Format("var _fromDateTextboxID = \"{0}\"; var _toDateTextboxID = \"{1}\"; ", dtFromdate.ClientID + "_dtFromdateDate", dtTodate.ClientID + "_dtTodateDate");
    this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", jc, true);
    

    Leave the button onclick unchanged, and now you might see what’s wrong – keep us updated.

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

Sidebar

Related Questions

I'm developing a solution which uses an ActiveX control (a commercial one which we
I'm developing a small utility application that needs to detect whether another one has
I have been developing pages and web parts in SharePoint 2007/2010 for the past
I am developing a SharePoint application which needs users from a specified Windows Server
Im developing one application which used SeekBar to control volume in MediaPlayer. The problem
I am developing one Windows phone 7 application. It has another project for unit
I am developing one android application which select wifi access point from list of
one of the programs I'm developing at work is reading the registry to figure
I am developing a Joomla component and one of the views needs to render
i'm developing a simple C# Editor for one of my university courses and I

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.