开发者

asp.NET HtmlInputText inside a disabled panel loses its value on postback

I have a asp.net page content as below. There i开发者_如何转开发s an HtmlInputText control inside a Panel which has Enabled="false". I set the Value property of HtmlInputText control in btnSet_Click and then set Enabled=true for the panel. After the postback finishes Value of the HtmlInputText is lost. Below is a list of cases i tried:

  • When I use asp:TextBox instead of HtmlInputText it works fine. But the above is a simplified demonstration of the usage of a complex user control. Basically, changing it is not an option.
  • When I place the panel and the buttons in an asp:UpdatePanel, it works fine again.
  • When I set disabled="disabled" (in the markup) for the HtmlInputText control, it works fine yet again.

What may be the cause of this behaviour?

<asp:Panel ID="pnl" runat="server" Enabled="false">
  <input type="text" runat="server" id="txt" />
</asp:Panel>
<asp:Button ID="btnSet" runat="server" Text="Set" OnClick="btnSet_Click" />
<asp:Button ID="btnEnable" runat="server" Text="Enable" OnClick="btnEnable_Click" />

--

protected void btnSet_Click(object sender, EventArgs e)
{
   txt.Value = "Test";
}

protected void btnEnable_Click(object sender, EventArgs e)
{
   pnl.Enabled = true;
}


Actually the HTML server controls (eg:) have no mechanism of identifying the capabilities of the client browser accessing the current page. But the Web server controls(eg:asp:TextBox) will not have browser compatibility issues as it takes care of itself.

Web server controls give u more freedom, flexibility and control over behaviour of these controls... so use them for your purpose.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜