Sharepoint 日期时间控件
我正在开发一个sharepoint webpart,其中我有2个日期时间控件,一个用于起始日期,另一个用于截止日期,我编写了一个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);
}
我在 Web 部件的 Createchildcontrol 方法中调用了此函数。
并且我在 Web 部件的 OnLoad 事件上添加了此代码
btnView.Attributes.Add("onclick", "DateMsg();");
请帮助我解决此问题...
仅供参考:此 btnView(按钮控件)是在运行时动态创建..
提前致谢...
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会采用不同的方式,以便更轻松地进行调试。
在 .aspx 文件中包含该函数:
并仅输出后面代码中的 ID:
保持 onclick 按钮不变,现在您可能会看到出了什么问题 - 让我们更新。
I would go in different way, allowing easier debug.
Have the function in the .aspx file:
And output only the ID from the code behind:
Leave the button onclick unchanged, and now you might see what's wrong - keep us updated.