Watermark Textbox cleared on partial postback

孤者浪人 提交于 2020-01-03 03:08:06

问题


when my page loads very first time i see the watermark on the textbox but if any postback on the page, the watermark is cleared, is there a way to hold that watermark on the textbox?

<head runat="server">
    <title></title>
    <script src="scripts/jquery-1.4.2.min.js" type="text/javascript"></script>
    <script src="scripts/jquery.watermark.min.js" type="text/javascript"></script>
    <script type="text/javascript">
         $(function () {
            $("#txtEmail").watermark("Email Address");
         });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtEmail" ErrorMessage="Email Invalid"></asp:RequiredFieldValidator>

    </div>
    </form>
</body>

回答1:


  1. go to the Scripts section in Firebug.
  2. select your HTML file in the drop-down.
  3. add a breakpoint on the line $("txtEmail").watermark.
  4. Debug using the console (check that the selector is successful, etc)



回答2:


 //for jquery ready
 $(function () {
      $("#<%= txtEmail.ClientID %>").watermark("Email Address");
 });

 //for partial postbacks 
 function pageLoad()
 {
      $("#<%= txtEmail.ClientID %>").watermark("Email Address");
 }


来源:https://stackoverflow.com/questions/10308074/watermark-textbox-cleared-on-partial-postback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!