HTML to ASP.net web form page - c#

i have this page ASP.Net Web Forms Page
<!-- Sidebar menu -->
<div id="sidebar-menu ">
<div id="topPanel"
<asp:Table runat="server" ID="table_PageHeader">
<asp:TableHeaderRow>
<asp:TableHeaderCell>
<asp:HyperLink ID="hyperlink_TruckList" runat="server" Text="Truck List" NavigateUrl="~/View/Trucklist.aspx" Font-Underline="false"></asp:HyperLink>
</asp:TableHeaderCell>
<asp:TableHeaderCell>
<asp:HyperLink ID="hyperlink_Reports" runat="server" Text="Reports" NavigateUrl="~/View/Reports.aspx" Font-Underline="false"></asp:HyperLink>
</asp:TableHeaderCell>
<asp:TableHeaderCell>
<asp:HyperLink ID="hyperlink_Profile" runat="server" Text="Profile" NavigateUrl="~/View/Profile.aspx" Font-Underline="false"></asp:HyperLink>
</asp:TableHeaderCell>
</asp:TableHeaderRow>
</asp:Table>
</div>
want to implement this
<!-- Sidebar menu -->
<div id="sidebar-menu">
<ul>
<li><i class="glyphicon glyphicon-info-sign" style="color:black"></i> Truck Data </li>
<li><i class="glyphicon glyphicon-folder-close" style="color:black"></i> Maintenance Record </li>
<li><i class="glyphicon glyphicon-calendar" style="color:black"></i> Maintenance Schedule </li>
</ul>
</div><!-- End div #sidebar-menu -->
</div><!-- End div .body .rows .scroll-y -->
</div>
<!-- END SIDEBAR -->
How can i insert the <li> and <i> in the Asp.net Web Form?
Thanks in advance

At you interacting with the elements server side? If not just add the HTML as is. ASPX pages work fine with HTML elements.
If you want to interact with the elements server side, give them an ID and add runat="server". E.g:
<div id="sidebar-menu" runat="server">
You can then access server side with sidebar-menu.

I believe you want to populate the unordered list from code behind. One option would be to make use of HtmlGenericControl class.
Your list item mark up looks like this
<li><i class="glyphicon glyphicon-info-sign" style="color:black"></i> Truck Data </li>
I believe the text should be within the <i></i> tags. So it should look like this.
<li><i class="glyphicon glyphicon-info-sign" style="color:black">Truck Data</i></li>
Based on this you can just have a placeholder in the aspx page and set it from code behind. Here in the example I am just populating a list item. Based on your needs you can loop/ create additional list items.
place holder in aspx
<asp:PlaceHolder ID="sidemenu" runat="server" />
code behind
HtmlGenericControl list = new HtmlGenericControl("ul");
HtmlGenericControl li = new HtmlGenericControl("li");
HyperLink a = new HyperLink();
a.NavigateUrl = "index.html";
a.Attributes.Add("style", "font-size: 18px; color: black");
HtmlGenericControl i = new HtmlGenericControl("i");
i.Attributes.Add("class", "glyphicon glyphicon-info-sign");
i.Attributes.Add("style", "color:black");
i.InnerText = "Truck Data";
a.Controls.Add(i);
li.Controls.Add(a);
list.Controls.Add(li);
sidemenu.Controls.Add(list);
namespace
using System.Web.UI.HtmlControls;
Generated markup
<ul>
<li>
<a href="index.html" style="font-size: 18px; color: black">
<i class="glyphicon glyphicon-info-sign" style="color:black">Truck Data</i>
</a>
<li>
</ul>

Related

Can't get the ID from a navbar list href

this is my first question, so hopefully I won't screw it.
This is .net framework 3.5
The MasterMenu.ascx has a navbar list and each item redirects to a specific url. And each item from the list has an ID.
What I'm (unsuccessfully) trying to do is, given the URL, get the ID of the item who send it there.
I.E. (MasterMenu.ascx):
<div id="navbar" class="collapse navbar-collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="dropdown" id="DropDownPF” runat="server" visible="false"><a id="A2" role="button" data-toggle="dropdown">PF<span class="caret"></span></a>
<ul class="dropdown-menu multi-level" role="menu" aria-labelledby="dropdownMenu">
<li visible="false" id="DropDepositSSN" runat="server">Deposit </li>
<li visible="false" id="DropPFSSN" runat="server">Check</li>
<li visible="false" id="DropInterfaceSSN" runat="server">Interface</li>
</ul>
</li>
When I get the current path, lets say
~/Check.aspx
I want a method that returns the id of the item:
DropPFSSN
Thanks in advance!

How do I insert a <p> tag into an ASP CheckBoxList's Checkboxes

I have a CheckBoxList that I am dynamically adding ListItems to in code-behind. It is defined as follows in the .ascx file:
<asp:CheckBoxList ID="cbl" runat="server" ClientIDMode="Static" RepeatLayout="UnorderedList"></asp:CheckBoxList>
This produces HTML that looks like this:
<ul id="cbl">
<li>
<input id="cbl_0" type="checkbox" name="M$content$PCDZ$M5TOPBM$ctl00$cbl$cbl_0" value="value">
<label for="cbl_0">label</label>
</li>
</ul>
Is it possible to insert a p-tag into the rendered html from the code-behind like so?
<ul id="cbl">
<li>
<p class="checkbox">
<input id="cbl_0" type="checkbox" name="M$content$PCDZ$M5TOPBM$ctl00$cbl$cbl_0" value="value">
<label for="cbl_0">label</label>
</p>
</li>
</ul>

How to change the text of a button inside a drop down list

<div id="ddlPreferences" runat="server" class="dropdown pull-left div-margin" visible="true">
<button class="btn btn-default dropdown-toggle" type="button" id="btnUser" data-toggle="dropdown">***Account***
span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="menu1">
<li role="presentation"><a role="menuItem" tabindex="-1" href="/Account/Profile.aspx">Profile</a></li>
<li role="presentation"><a role="menuItem" tabindex="-1" href="/Account/Logout.aspx">Logout</a></li>
<li role="presentation"><a role="menuItem" tabindex="-1" href="/Account/ChangePassword.aspx">Change Password</a></li>
<li role="presentation"><a role="menuItem" tabindex="-1" href="/Account/Upload.aspx">Upload Post</a></li>
<li role="presentation"><a role="menuItem" tabindex="-1" href="/Account/Administration.aspx">Account Management</a></li>
<li role="presentation" class="divider"></li>
</ul>
</div>
I am trying to dynamically change the word account on the second line to the current users user name I have tried a couple of things but cannot seem to make it work. Any advice would be welcomed.
Add a label and you can then change it behind code.
asp:label id="lblUpload" runat="server" text="upload">
Code behind :
lblUpload.text ="dynamic value"
You can also use a html input label.
Replace html button with
<asp:button id="id" runat="server" text="urText" />
Then whenever u want to change text, change it via code as:
id.Text="Your desired text";

transfer value from master page to another master page

i want to know if it is possible to transfer a value from a master page to anotehr master page? i want to transfer my "Name" value to the next masterpage. images shown below
the name "Jedi Ablaza" will be transffered into the next master page
and my code for my first master page
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a runat="server" href="~/" style="color: white">Home</a></li>
<li id="forHR" runat="server" class="dropdown">
<a id="hr" class="dropdown-toggle" runat="server" data-toggle="dropdown" href="#" style="color: white">HR</a>
<ul class="dropdown-menu">
<li>Core Values</li>
<li>Rater & Employee Relation</li>
</ul>
</li>
<li>
<a id="toMosef" runat="server" href="MOSEF/WebForm1.aspx" style="color: white">MOSEF</a>
</li>
to the highlighted portion of the new masterpage.
how can I do that? thanks!
Use Sessions.
Assign to the session:
Session["username"] = txtusername.text;
retrieve from the session:
string username = Session["username"].toString();

Using n2cms, How do I stop a div from automatically wrapped around my user controls

I'm trying to create a part which is essentially a list
<ul>
<n2:DroppableZone ID="zoneSlideshowItems" ZoneName="SlideshowItems" AllowExternalManipulation="true" runat="server"></n2:DroppableZone>
</ul>
I have another part that i drop multiple times onto the above zone:
<li>
<a href="<%= CurrentItem.Link %>">
<img src="<%=CurrentItem.ImageUrl %>" alt="<%= CurrentItem.Title %>" />
<div class="overlayBox">
<h1><%= CurrentItem.OverlayHeader %></h1>
<p><%= CurrentItem.OverlayText %></p>
</div>
<div class="overlayBoxBack">
</div>
</a>
</li>
However when i look at the page source, its adding a div around each element that i drop onto the zone:
<div class='uc slideshowItem'> <<<< That Guy!!
<li>
<a href="http://gigpig.fm">
<img src="/Upload/skal.jpg" alt="Anthony is Jacinta" />
<div class="overlayBox">
<h1>Anthony</h1>
<p>im trying to tell you something</p>
</div>
<div class="overlayBoxBack">
</div>
</a>
</li>
</div>
Does anyone know how to stop that div from being generated?
Cheers!

Categories

Resources