如何在每个页面上调用主页面Javascript验证 [英] How to call Master page Javascript validation on each page

查看:53
本文介绍了如何在每个页面上调用主页面Javascript验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在母版页上有按钮和文本框。我想通过JavaScript验证文本框是否为必需。它应该适用于每个contentPage.Please帮助我...

I have Button and Textbox on Master page. I want to validate textbox as Required through JavaScript. And it should work on each contentPage.Please Help me...

推荐答案

见下文..



See below..

<asp:button id="btnsendrequest" runat="server" text="Submit" onclientclick="return validaterequirment()" xmlns:asp="#unknown" />





以下Javascript代码..





Javascript code below..

function validaterequirment()
{
    if (document.getElementById("<%=TextBox1.ClientID%>").value=="")
      {
         document.getElementById("<%=TextBox1.ClientID%>").Style.add("border","solid 1px red");
         return false;
      }
}



在您的母版页中写上面的代码。它适用于所有内容页面。 TextBox1是文本框的id。如果y = textbox1值为空,则其边框颜色变为红色并避免回发。


Write above code in your master page. It will work in all content pages. TextBox1 is id of textbox. If y=textbox1 value is empty its border color become red and avoid postback.


您从母版页处理表单提交事件并检查文本框值。如果为空,则返回false,否则返回true。返回false表示您的表单不会提交给服务器。 True意味着它可以进一步处理。


you handle form submit event from your master page and check your textbox value. If it is empty then return false else return true. Return false means your form will not submit to the server. True means it can process further.


(''#yourFormId'')。submit(function(){

返回!
(''#yourFormId'').submit(function() {
return !


这篇关于如何在每个页面上调用主页面Javascript验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆