replace controls in <li> - c#

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>

I would have both controls in the li, then only show/hide the one you want, using the Visible property.

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.

You have to read about "Page.FindControl Method (String)".
There is some sample as well.

You can also use
Page.Controls.Remove(btnUpload);
and then create the hplnkViewDocument as new LinkButton control
Page.Controls.Add(hplnkViewDocument);

;-)
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

Related

Why does the for attribute from the label tag is not working in userControl.ascx?

i Have this line of code :
<label id="lblinput" class="input-label" runat="server" for="fUpload">
<i class="fa fa-upload" aria-hidden="true"></i>
<span id="label-span">Select files to upload</span></label>
<asp:FileUpload ID="fUpload" runat="server" AllowMultiple="true" CssClass="fUpload"/>
and is placed inside a usercontrol, which i load in a modal to load files into a database. I wanted to style the button for choosing files so i hid it and gave the label it's id .. as i understand that is the only way to style the FileUpload controller from asp.
the problem is that it does not work when placed in a usercontrol .. i tried it in a regular aspx page and it works there. Do you have any idea why that is ?
thank you :)
Solved:
i added ClientIDMode and set it to static in the asp:FileUpload and it works now

unable to access a control in Master file from the code behind

basically I have a button in my navbar which is defined in master file. And I want to call a c# method when that button**(bt)** is clicked.
But I can not access the control in code-behind. I also need to control visibility, so I believe it has to stay in one of those Views.
<asp:GridView runat="server" ID="lw3">
<EmptyDataTemplate>
<ul class="nav navbar-nav navbar-right" style="color:#ffffff !important">
<li><a runat="server" href=""></a></li>
<li><a runat="server" href="" title=""></a></li>
<li><a runat="server" id="btout">bt</a></li>
</ul>
</EmptyDataTemplate>
</asp:GridView>
Put the <a> link outside of Gridview to directly access in code behind.
If you still want to put inside the grid then you will be able to access these <a> link through grid by doing lw3.FindControl.
After you get access to those control then you will be able to control visibility as well by doing:
btout.Visible = true; or
btout.Visible = false;
I Hope this will help you.

How to add literals to panels in codebehind, in order to create a dashboard-like layout grid?

Currently this is working:
<div id="DashboardDiv" runat="server">
<asp:Panel ID="pnlA" runat="server" CssClass="Widget" Width ="900">
<asp:Literal ID="ltrChart" runat="server"></asp:Literal>
</asp:Panel>
<asp:Panel ID="pnlB" runat="server" CssClass="Widget" Width ="900">
<asp:Literal ID="ltrChart2" runat="server"></asp:Literal>
</asp:Panel>
</div>
I need to use a literal, in order to use dotNet Highcharts in codebehind.
The problem however, is that I'm creating a Dashboard which will display multiple widgets. Right now my testcase consists of 1 widget, but I want to eventually expand that to an indetermined number of widgets.
I feel that I need to create panels (and literals added to these), based on the amount of widgets a user wants, on run-time. How do I do this?
I tried something like this:
protected static List<Panel> panelList = new List<Panel>();
Panel myChildPanel = new Panel();
myChildPanel.Width = 900;
panelList.Add(myChildPanel);
DashboardDiv.Controls.Add(myChildPanel);
And then adding the literal to this List of Panels, to a specified panel:
Literal ltrChart = new Literal();
ltrChart.Text = chart.ToHtmlString();
panelList[counter].Controls.Add(ltrChart);
This feels like an ugly way of doing things.
Basically I'm looking for this:
How can I create panels/areas/zones that are capable of containing a Literal, in code-behind, so that I can create a dashboard filled with widgets-look?
Have you tried using asp placeholders? I believe they will help you acheive what you want to do. They allow you to place and kind of controls in them and you can hide and show a placeholder based on a specific condition. For example
<asp:Placeholder runat="server" visible="<%=CMSContext.CurrentUserIsAuthenticated()%> >
<div class="faq-listing itmList faq odd">
<h2 class="heading"> Home</h2>
<asp:Repeater ID="rptSubFaq" runat="server">
</asp:Repeater>
</div>
</asp:Placeholder>

How do I manipulate the text in my Site.Master file in codebehind

I would like to carry out some string operations on the username in my Site.Master page before rendering it on the page.
Here's what the current code looks like:
<div class="login">
<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
<LoggedInTemplate>
Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /></span>
</LoggedInTemplate>
</asp:LoginView>
</div>
For some reason, I cannot reference HeadLoginName.Text or something similar. What am I missing here?
Thanks for looking.
Possible Duplicate:
Find control in loginview
It is necessary to find the "HeadLoginName" control inside the "HeadLoginView" container first and then specify its Text property (see the Find Control with in LoginView control blog post for more information):
LoginName ln = (LoginName)HeadLoginView.FindControl("HeadLoginName");
ln.Text = ...;

How to open one single popup window for multiple onclick event of anchor tag?

I have one aspx page with 1000 anchor tag.
I want to open single popup onclick of anchor tag & display data in popup window from database dynamically.
I want to use only one popup in my page.
For 1000 anchor tag inner data of popup will change with respect to anchor click change.
<h5><a href="#" runat="server" >Advertise & Media</a>
<em>
2 entries
</em>
</h5>
<ol>
<li><a id="advMedia1" runat="server" href="#" onclick="advMedia1_onclick">Advertise Agency</a></li>
<li><a runat="server" runat="server" href="#">Magazine</a></li>
<li><a runat="server" runat="server" href="#">Press</a></li>
<li><a runat="server" runat="server" href="#">Weekly</a></li>
</ol>
The window.open() function accepts the name of the window as the second parameter.
window.open(url, name);
When you already have a popup window with the same name open, your browser will reuse that window.
So for example
window.open('/Page1.aspx', 'SameWindow');
window.open('/Page2.aspx', 'SameWindow');
window.open('/Page3.aspx', 'SameWindow');
window.open('/Page4.aspx', 'SameWindow');
These will all open in the same window.
you could try to update the data for your popup panel

Categories

Resources