我的代码格式如下:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="Text1" runat="server"></asp:TextBox>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="Text2" runat="server"></asp:TextBox>
<asp:Button ID="Submit" runat="server" OnClick="Submit_Click"
Text="Click Me"/>
</ContentTemplate>
</asp:UpdatePanel>
当我单击Submit(提交)按钮时,所有表单都重新发布到了服务器上(Text1和Text2)。但我只想在UpdatePanel(Text2)中发回文本框,有可能实现吗?感谢您的回复!
我有使用Javascript的解决方案:
function onSubmit() {
var text1 = this.document.getElementById('<%=Text1.ClientID%>');
text1.disabled = true;
return true;
}
....
<asp:Button ID="Submit" OnClientClick="onSubmit();" ..../>
这将导致Text1在回发之前被禁用,它表明ASP.NET不会从禁用的文本框中回发值,其似乎仅在没有UpdatePanel的情况下有效。 当然,回发后Text1为空。
Well, the UpdatePanel controls what get's posted back. You cannot change that behavior. It should be posting the form data for the UpdatePanel only (I believe), plus the entire ViewState. It has to post the entire ViewState for the page lifecycle to work.