12

I've got a button on my page in code behind I do this:

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

But later I want to show that button so I tried this:

btnSaveLineItems.Style.Clear();

This doesnt appear to reshow the button... The html markup in the beginning has a "style=display:none;" in the beginning of the page.. and it maintains that style even though I try to remove it?

When my page first starts up I have this:

btnSaveLineItems.Style["display"] = "none";

This renders like the following in HTML:

<input type="submit" name="ctl00$MainContent$btnSaveLineItems" value="Save" id="MainContent_btnSaveLineItems" title="Save changes?" style="border-color:#4B6C9E;border-style:Solid;display:none;" />

Then an event happens (selected index changed event of a drop down box) where I then do this:

btnSaveLineItems.Style["display"] = "";

I've also tried:

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

and both render the same HTML:

<input type="submit" name="ctl00$MainContent$btnSaveLineItems" value="Save" id="MainContent_btnSaveLineItems" title="Save changes?" style="border-color:#4B6C9E;border-style:Solid;display:none;" />

0

4 Answers 4

16

You can remove that style in this way:

 btnSaveLineItems.Style["display"] = ""; 

or

btnSaveLineItems.Style.Remove("display"); 

Edit:

That doesnt work for me either...I wonder if it is because of the drop down list box is inside of an update panel and this button is outside of the updatepanel?

Yes, you can only update the content of the current UpdatePanel in an asynchronous postback by default. The easiest would be to put your Button in another UpdatePanel and add the DropDownList as AsyncPostBackTrigger:

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DdlChanged"> <asp:ListItem Text="Item 1" Value="1"></asp:ListItem> <asp:ListItem Text="Item 2" Value="2"></asp:ListItem> </asp:DropDownList> </ContentTemplate> </asp:UpdatePanel> <asp:UpdatePanel ID="UpdatePanel2" runat="server"> <ContentTemplate> <asp:Button ID="btnSaveLineItems" Text="click me" runat="server" /> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="DropDownList1" /> </Triggers> </asp:UpdatePanel> 
Sign up to request clarification or add additional context in comments.

11 Comments

That doesnt work for me either...I wonder if it is because of the drop down list box is inside of an update panel and this button is outside of the updatepanel?
The first line you gave cannot be valid javascript
@TimSchmelter if you are manipulating dom, it's javascript. If this is some other language that generates the actual javascript that does the job, then it's fine. Is it?
@TimSchmelter it looks like assigning to function call is not valid in that language either ? ;) I removed my downvote no hard feelings.
@nickbork, Tim's code mentioned above is correct. I have checked my side.
|
2

this works :

gv.Style.Add(HtmlTextWriterStyle.Top, "-44px"); 

to add the style

and

gv.Style.Remove("top"); 

to remove the style

Comments

1
btnSaveLineItems.Style["display"] = "block"; 

7 Comments

It's a tested code. When you need to show the Button, set the display attribute to block. That's it :)
No thats not it, the rendered html comes out as <input type="submit" name="ctl00$MainContent$btnSaveLineItems" value="Save" id="MainContent_btnSaveLineItems" title="Save changes?" style="border-color:#4B6C9E;border-style:Solid;display:none;" /> I have debugged my code.
Start with a sample application. and check with a Button only. Set the Attribute to block at Form load and set the Display to none in designer. Once the Page loads it will show you Button. I assume you have some other issue connected with this.
Its probably because my event is inside of an updatepanel and the button is outside of the updatepanel. That is why this is happening...
Can you tell something ? which event?
|
0

You can Just add the class d-none by getting it class name and then remove the class d-none where you want to show the button.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.