开发者

How to modify style for an asp:textbox in codebehind?

I am trying to set the style of an asp:TextBox in cod开发者_开发问答ebehind, the textbox is style is set initially to style="display:none" when I set the dispaly to block in codebehind the textbox appears for a moment and then it's gone. I don't know what this problem is, when it's done in javascript it works fine

Here is the code:

asp.net code:

<asp:TextBox ID="txtError" style="display:none" runat="server" ReadOnly="True" Width="95%"></asp:TextBox>

codebehind:

txtError.Style["display"] = "block";

Am I doing anything wrong? Thanks in advance.


If you use

txtError.Visible = false; 

You can not access the text box using JavaScript. If you want to just change visibility you can use

txtError.Style.Add("display", "none");


Any .NET control has Visible property - you should use it in case you don't need control to be shown later (if Visible is set to false control won't be rendered at all).

Regarding your issue - I think there is some client (javascript) code that changes style of textbox back to display:none;


What about setting the Visible property?

txtError.Visible = false;

If this also doesn't work then somewhere else you will be re setting the value to none. Also check whether any of the parent elements of the textbox is not hidden.

Also no need to set the display of a textbox to block(if not intended so), use inline instead.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜