2012-03-03 4 views
1

UpdatePanel에서 AutoPostback이 true로 설정된 DropoutList와 jQuery.watermark 플러그인이 적용된 텍스트 필드를 배치하면 워터 마크가 텍스트 필드에서 지워지지 않습니다. 드롭 다운 목록이 변경되었습니다.UpdatePanel에서 DropdownList를 사용할 때 워터 마크가 서버에 게시 됨

텍스트 필드의 워터 마크가 올바르지 않은 텍스트 필드의 값으로 서버에 게시됩니다. UpdatePanel을 사용하지 않으면 워터 마크 값이 플러그인의 양식 제출 코드에 의해 올바르게 지워집니다.

내가 수집 할 수있는 것은 DropdownList에 대해 생성 된 포스트 백이 JavaScript에서 워터 마크 값을 지우는 방법 인 양식의 제출 이벤트 핸들러를 우회하여 완료된다는 것입니다. 다양한 ASP.NET AJAX JavaScript events은 게시물 본문이 작성된 후에 모두 해고되므로 워터 마크를 제거하는 데 사용할 수 없습니다. 이 일을하는 다른 방법이 있습니까?

이것은 위치 표시기 특성을 기본적으로 지원하지 않는 브라우저, 특히 IE9 이하에서만 적용됩니다.

나는 raised this as a bug for the plugin here입니다.


    <form id="form1" runat="server"> 
    <asp:ScriptManager runat="server" /> 
    <div> 
     Demonstration. 
     <br /> 
     <br /> 
     Note: This is only a problem for browsers that do not have have text field placeholder support. Most notabily Internet Explorer 9 and below. 
     <ol> 
      <li>The text field has a watermark 'wattery' applied to it</li> 
      <li>The dropdown list is set to auto postback</li> 
      <li>When you change the dropdown list the watermark is not removed and is posted to the server as the value of the text field</li> 
      <li>When you click either the button or the link the watermark is removed as these actions trigger the 'beforeunload' event.</li> 
     </ol> 
     <asp:UpdatePanel runat="server"> 
      <ContentTemplate> 
       <asp:TextBox runat="server" ID="txt" /> 
       <asp:DropDownList runat="server" ID="ddl" AutoPostBack="true" 
        onselectedindexchanged="ddl_SelectedIndexChanged"> 
        <asp:ListItem Text="one" /> 
        <asp:ListItem Text="two" /> 
       </asp:DropDownList> 
       <asp:Button Text="Click me 1" runat="server" /> 
       <asp:LinkButton Text="Click me 2" runat="server" /> 
       <br /> 
       <br /> 

       Value from text field after postback = '<asp:Label Text="" runat="server" ID="lbl" />' 
      </ContentTemplate> 
     </asp:UpdatePanel> 
    </div> 
    </form> 

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js" ></script> 
    <script type="text/javascript" src="js/jquery.watermark.js" ></script> 
    <script type="text/javascript"> 

     $().ready(function() { 
      $('#<%=txt.ClientID %>').watermark("wattery"); 
     }); 

    </script>
protected void ddl_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    lbl.Text = txt.Text; 
} 

답변

0

꽤 오래된 스레드를하지만, 최근에이 문제를 가지고 :

코드는이를 재현한다. 여기에 내가 생각해내는 것이있다.

$('#<%=Button1.ClientID%>').click(function() { 
       if (typeof("Page_ClientValidate") === "function") { 
        if (Page_ClientValidate()) { 
         $.watermark.hideAll(); 
        } 
        else { 
         $.watermark.showAll(); 
        } 
       } 
       else { $.watermark.hideAll(); } 
}); 

참고 : 100 % 테스트하지는 않았지만 그 행에있는 것이 작동해야합니다.

관련 문제