1
如果將應用了jQuery.watermark插件的文本字段和在UpdatePanel中將AutoPostback設置爲true的DropdownList置於水平,則不會從文本字段中清除水印下拉列表已更改。在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;
}