Reputation: 2911
How do i replace the controls in a list item using server side code. I need to replace this
<li>
<asp:LinkButton ID="btnUpload" runat="server" OnPreRender="btn_PreRender" CommandName="Uploader"
TabIndex="2">Upload</asp:LinkButton>
or <a target="_blank" href="../PersonalInfo/MailingAddress.htm">Mail</a> the form.
</li>
with
<li>
<asp:LinkButton ID="hplnkViewDocument" runat="server" Text="View Document" SkinID="lnkBtnBlue"></asp:LinkButton>
</li>
Upvotes: 3
Views: 142
Reputation: 2973
;-)
If you wanted to be super lazy you could just wrap the either of them in a span with a given class and then add some css to the page head (assuming it runs at server) that has display:none; visiblity: hidden; for the class that shouldn't show
HTML:
<li>
<span class="one">
<asp:LinkButton ID="btnUpload" runat="server" OnPreRender="btn_PreRender" CommandName="Uploader" TabIndex="2">Upload</asp:LinkButton>
or <a target="_blank" href="../PersonalInfo/MailingAddress.htm">Mail</a> the form.
</span>
<span class="two">
<asp:LinkButton ID="hplnkViewDocument" runat="server" Text="View Document" SkinID="lnkBtnBlue"></asp:LinkButton>
</span>
</li>
Make sure to add either:
.one {display:none; visiblity: hidden;}
...or
.two {display:none; visiblity: hidden;}
...based on your runtime needs
Upvotes: 0
Reputation: 1592
I believe you can put a pannel or some server side control that works as a container. Then you can add or remove from their controls collection whatever controls you like.
Lets say a pannel that you want to add a button to, just to give you an idea:
Button button = new Button ();
//Set properties accordingly
Pannel1.Controls.Add(button);
Also, Controls is a property of Control, so you will find it in any class that inherits Control. Even the page inherits from a class that inherits from control.
Upvotes: 1
Reputation: 2689
You can also use
Page.Controls.Remove(btnUpload);
and then create the hplnkViewDocument
as new LinkButton control
Page.Controls.Add(hplnkViewDocument);
Upvotes: 0
Reputation: 37642
You have to read about "Page.FindControl Method (String)".
There is some sample as well.
Upvotes: 0
Reputation: 12157
I would have both controls in the li
, then only show/hide the one you want, using the Visible
property.
Upvotes: 3