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

StackOverflow https://stackoverflow.com/questions/5992289

  •  13-11-2019
  •  | 
  •  

سؤال

I have a asp.net page content as below. There is 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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top