C# Sharepoint日期时间控件

C# Sharepoint日期时间控件,c#,javascript,sharepoint,web-parts,datetimepicker,C#,Javascript,Sharepoint,Web Parts,Datetimepicker,我正在开发一个sharepoint Web部件,其中我有两个日期时间控件,一个用于起始日期,另一个用于截止日期,我编写了一个javascript函数来验证用户输入的日期。如果截止日期小于起始日期,它将发出警报。我将这个JS函数作为属性添加到按钮点击中。但当我单击时,此函数未执行 我正在使用以下内容添加代码: void Registerscript() { string jc = @"<script> function DateMsg()

我正在开发一个sharepoint Web部件,其中我有两个日期时间控件,一个用于起始日期,另一个用于截止日期,我编写了一个javascript函数来验证用户输入的日期。如果截止日期小于起始日期,它将发出警报。我将这个JS函数作为属性添加到按钮点击中。但当我单击时,此函数未执行

我正在使用以下内容添加代码:

  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);
    }
请帮我解决这个问题

仅供参考:此btnView(按钮控件)是在运行时动态创建的


提前感谢…

我将以不同的方式进行调试,以便更轻松地进行调试

在.aspx文件中具有以下功能:

<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>
单击按钮时保持不变,现在您可能会看到出了什么问题-让我们不断更新

<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>
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);