How to set a div coming from master file as hidden in some other aspx page? - html

I have check.aspx file which has:
<%# MasterType VirtualPath="~/MSW.master" %>
And in this master file I have:
<%# Register Src="UserControls/Common/StatusBar.ascx" TagName="StatusBar" TagPrefix="uc3" %>
And in this StatusBar.ascx, I have a div:
<div id="status_box_content">
<asp:Label ID="lblWelcome" runat="server" Text="Welcome " ></asp:Label>
<asp:Label ID="lbUser" runat="server"meta:resourcekey="lblFullNameResource1"></asp:Label>
<asp:Label ID="lblPartnerInfo" runat="server" ></asp:Label>
<asp:HyperLink Font-Underline="False" NavigateUrl="~/profile/Logout.aspx"
ID="HLinkLogout" runat="server" meta:resourcekey="HLinkLogoutResource1">Logout</asp:HyperLink>
</div>
I want this div with id ="status_box_content" to be invisible in check.aspx file. But everything else from master file is needed.
How do I make the div invisible while keeping the master file?

In your check.aspx, hide the div using jquery. It works perfectly fine. I was making a huge mistake while calling it.So yeah,it works! :)

Notes: Make your div runat="server"
Aspx Page
<div id="status_box_content" runat="server">
<asp:Label ID="lblWelcome" runat="server" Text="Welcome " ></asp:Label> <asp:Label ID="lbUser" runat="server"meta:resourcekey="lblFullNameResource1"></asp:Label>
<asp:Label ID="lblPartnerInfo" runat="server" ></asp:Label>
<asp:HyperLink Font-Underline="False" NavigateUrl="~/profile/Logout.aspx"
ID="HLinkLogout" runat="server" meta:resourcekey="HLinkLogoutResource1">Logout</asp:HyperLink>
</div>
Code Behind Page : Put This Code in your content page_load event
HtmlGenericControl DivCount = (HtmlGenericControl)Page.Master.FindControl("status_box_content");
DivCount.Visible = false;

Make runat= server to your div.
And then on page load of check.aspx use make that div invisible:
this.Master.findcontrol("divname").visible= false;

As the div is inside UserControl and User Control is inside Master Page, just try to access UserControl First in your page, then find out div and make it invisible. You could try out this:
First make the div as server control,Add runat="server" in div :
<div id="status_box_content" runat="server">
UserControl uc = ((UserControl)this.Master.FindControl("ucTopUser"));
HtmlGenericControl div = (HtmlGenericControl )uc.FindControl("status_box_content");
div.Visible = false;

Related

How to change width in TemplateField using Eval

I have a Gridview contains many Template-Fields.
I want to make the width of a label in my html source equal to a value saved in my database. Here is the code I am trying but it is not working:
<asp:TemplateField HeaderText="Status" ItemStyle-Width="200px">
<ItemTemplate>
<asp:Label BackColor="#6699ff" Width="<%#
Eval("Status").ToString() %>" runat="server"> </asp:Label>
<%# Eval("Status").ToString() %>%
</ItemTemplate>
</asp:TemplateField>
U can do something like this:
span.gridLabel
{
display:block;
/*You can change to display:inline-block if you want Label and %Value in same line.*/
}
And your template field:
<asp:TemplateField HeaderText="Status" ItemStyle-Width="200px">
<ItemTemplate>
<span class="gridLabel" style='width:<%# Eval("Status").ToString() %>px; Background:#6699ff'> </span>
<%# Eval("Status").ToString() %>%
</ItemTemplate>
</asp:TemplateField>

How to change the css class of list which is inside an asp repeater when clicking an asp link button?

I am trying to build a three level left navigation for my application using asp.net repeater and html list
I have three nested repeater with a linkbutton inside
when i click the linkbutton the list class should be active ( i have css for this active class).I am not good in Jquery
below is my code ( now i used only two repeater),Kindly help me how can i do this?
<ul class="nav nav-list mb-xl show-bg-active">
<asp:repeater ID="rep1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<li class="">
<asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Eval("Menu") %>'></asp:LinkButton>
<asp:repeater ID="rep2" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<ul>
<li>
<asp:LinkButton ID="LinkButton2" CommandArgument="id" runat="server" Text='<%# Eval("Menu") %>'></asp:LinkButton>
</li> </ul>
</ItemTemplate>
</asp:repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:KTCWEBConnectionString %>" SelectCommand="SELECT NAVIAGATE_1.Menu FROM NAVIAGATE INNER JOIN NAVIAGATE AS NAVIAGATE_1 ON NAVIAGATE.ID = NAVIAGATE_1.ParentID WHERE (NAVIAGATE.Menu = #menu)">
<SelectParameters>
<asp:ControlParameter ControlID="LinkButton1" Name="menu" PropertyName="text" />
</SelectParameters>
</asp:SqlDataSource>
</li>
</ItemTemplate>
</asp:repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:KTCWEBConnectionString %>" SelectCommand="SELECT DISTINCT Menu, ParentID, ID FROM NAVIAGATE WHERE (NOT (ParentID IS NULL)) AND (ParentID = 2)"></asp:SqlDataSource>
</ul>
So it's been a while since I've done ASP.Net controls but...
Your inner lists would need to bind the Enabled property to something in your Controller. Then when something is clicked you just set that binding to false. This should in turn disable all those buttons and if your css is written correctly (tier2:disabled) it should pick it up correctly.
That said, if this is a new application, stop using ASP.NET controls, it should have been killed a long time ago. HTML + CSS + ReactJs or KnockoutJs is the way to go now-a-days!

Change style of an item inside updatepanel dynamically

I have an image inside an updatepanel. When I click on the image it needs to be highlighted. I use addclass and removeclass to make this work, if it is outside updatepanel. When I put the image inside the updatepanel, the css is applied but then reverts to original after the update completes and the page is rendered.
How can I change the styling of the image inside the updatepanel dynamically?
Markup:
<asp:UpdatePanel ID="UpdatePanel2" runat="server" class="journey-categories">
<ContentTemplate>
<ul class="journey-categories">
<asp:Repeater ID="rptJourneyCategories" runat="server">
<ItemTemplate>
<li>
<a href="javascript:void(0)" data-categoryid="<%# Eval("Id") %>" data-introtitle="<%# Eval("IntroTitle") %>" data-introtext="<%# Eval("IntroText") %>">
<img class="thumb" src="<%# Eval("CategoryIcon") %>" width="70" height="70" alt="" id="imgCategoryIcon" />
</a>
<span><%# Eval("Title") %></span>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
</ContentTemplate>
</asp:UpdatePanel>
Jquery:
$('[data-categoryid]').off('click.categories').on('click.categories', function () {
$(this).closest('ul').find('li.selected').removeClass('selected');
$(this).parent().addClass('selected');
});
I got this to work with the help of EndRequestHandler
I added the following inside script document ready and it updated the styling after the update panel completed.
<script type="text/javascript">
$(function () {
var onDomReady = function () {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler() {
var type = $('[id$=ddlType]').val();
$('a[data-categoryid="' + type + '"').parent().addClass('selected');
}
}});

Eval format in textbox

I have been trying to apply Eval on textbox which its mode is TextMode="Date". The date is not loading in to the text box and this is because the textmode. It seems to be that the Eval format is not working at all. When I remove the textmode it works. I have been trying several on variations and non of them have worked.
Here is some of them:
<asp:TextBox ID="birthdayTB" runat="server" Text='<%# Convert.ToDateTime(Eval("Birthday")).ToString("d") %>' TextMode="Date"></asp:TextBox>
<asp:TextBox ID="birthdayTB" runat="server" Text='<%# Eval("Birthday", "{0:dd-MM-yyyy}") %>' TextMode="Date"></asp:TextBox>
<asp:TextBox ID="birthdayTB" runat="server" Text='<%# Eval("Birthday", "{0:d}") %>' TextMode="Date"></asp:TextBox>
How can I make this work?
Thank you.
Use on code behind
birthdayTB.Text = Convert.ToDateTime(Birthday).ToString("dd-MM-yyyy");

ASP.NET ContentPlaceHolder - How to Register Data within MySql

I have 2 MasterPages (A main MasterPage and Simple MasterPage) I use only the Simple one with my other pages. Here part of my program:
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
<div id="main_content">
<div id="description">
<br />
Name : <asp:TextBox ID="TextName" Text="" runat="server" />
Image :<asp:Image ID="Image1" runat="server" Height="20px" />
...</div></asp:Content>
How to register data (ex. name) and an image in a database?
I tried with:
name = Request.Form["ctl00$ContentPlaceHolderMainContent$TextName"];
name = Request.Form["ctl00$MainContent$TextName"];
img = ???
But I only saw a space with NULL in the database.