Jump to content

Changing the class of a div tag using dot net (C#)


FrostbiteXIII

Recommended Posts

Hey guys, gave up on the pdf printing - decided it might be nicer to just use asp.net to create a new printer friendly page - basically I am using panels and switching their visibility depending on which version I want shown (via a querystring)...However there are some styles that need to change for the main div tags... I have set two different styles for the outlying div tags in my css file. Can anyone tell me the best way to change between these?I currently have something like:

<body>	<form id="form1" runat="server">		<asp:Label id="lvl0section" runat="server">	<asp:Label id="lvl1section" runat="server">......load o' code.......	</asp:Label>	</asp:Label>	</form></body>

My Page Load function looks something like:

protected void Page_Load(){		// Show or hide the Panel contents.		if (Request.QueryString["printme"] == "true")		{			Normal_W3CImages.Visible = false;			Print_W3CImagesGap.Visible = true;			Label["lvl0section"].class = "lvl0section_print";			Label["lvl1section"].class = "lvl1section_print";		}		else		{			Normal_W3CImages.Visible = true;			Print_W3CImagesGap.Visible = false;			Label["lvl0section"].class = "lvl0section_normal";			Label["lvl1section"].class = "lvl1section_normal";		}}

Obviosuly its the bold 4 lines starting 'Label' that are wrong - am I on the right lines? Can anyone tell me where I am going awry? :)Thanks!Bob

Link to comment
Share on other sites

Rather than:

Label["lvl0section"].class = "lvl0section_print";Label["lvl1section"].class = "lvl1section_print";

Try:

lvl0section.CssClass = "lvl0section_print";lvl1section.CssClass = "lvl1section_print";

Link to comment
Share on other sites

OK, Im trying out this fancy 'RTFM' method...But still not getting very far:

protected void Page_Load(){		if(!IsPostBack){			currentYear.Text = DateTime.Now.ToString("yyyy");						filename = Request.ServerVariables["PATH_TRANSLATED"];			objFI = new System.IO.FileInfo(filename);			modifiedDate.Text = objFI.LastWriteTime.ToString("MMMM dd, yyyy");		}				// Show or hide the Panel contents.		if (Request.QueryString["printme"] == "true")		{			Normal_W3CImages.Visible = false;			Print_W3CImagesGap.Visible = true;			lvl0div_print.Disabled = true;			lvl1div_print.Disabled = true;			lvl0div_normal.Disabled = true;			lvl1div_normal.Disabled = true;		}		else		{			Normal_W3CImages.Visible = true;			Print_W3CImagesGap.Visible = false;			lvl0div_print.Disabled = true;			lvl1div_print.Disabled = true;			lvl0div_normal.Disabled = true;			lvl1div_normal.Disabled = true;		}

Doesnt stop the div tags:

<div id="lvl0div_print" class="lvl0section_print" runat="server">	<div id="lvl1div_print" class="lvl1section_print" runat="server">	<div id="lvl0div_normal" class="lvl0section_normal" runat="server">	<div id="lvl1div_normal" class="lvl1section_normal" runat="server">

From being disabled (all of the tags and their styles still seem to apply)...Any ideas? :)

Link to comment
Share on other sites

Oooh, thanks Jesh - my RTFMing took awhile, so my repy was quite delayed from when I started! :)
Thanks again Jesh - works a treat!Was so happy - It all now looks *perfect* in Firefox! All code is validating - including my css... Then I tried IE7...F*ing div tags (well... I *think* its the div tags)! :)
Link to comment
Share on other sites

Hehe. You might try rendering out the page in IE, viewing the source as IE sees it, and then pasting that in a new topic in the CSS forum. It could be the CSS that IE is having troubles with.

Link to comment
Share on other sites

Hehe. You might try rendering out the page in IE, viewing the source as IE sees it, and then pasting that in a new topic in the CSS forum. It could be the CSS that IE is having troubles with.
OK, its taken me this long, and Ive pulled |''''|''''| much of my hair out, but Ive norrowed it down! Will now make a new css topic!Thanks again!
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...