tags:

views:

229

answers:

2

Hi all, I am trying to set the style of an asp:TextBox in codebehind, 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.

A: 

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.

rahul
+1  A: 

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;

Andrew Bezzub
I found that there is a Window.Load event in the javascript code that resets the property. Thanks a lot
Fahad