Forum Moderators: open
I have a bit of code in my master page cs file that assigned a value to "pageid".
In the master page I am loading in a handler for CSS:
<link href="/dotnettemplate/style/style.ashx?pageid=" rel="stylesheet" type="text/css" />
I have tried editing it to:
<link href="/dotnettemplate/style/style.ashx?pageid=<%=pageid%>" rel="stylesheet" type="text/css" />
(like I would do for classic ASP), but it doesn't convert it.
The code in the master.cs file that assigns the value to the pageid is below:
protected void Page_Load(object sender, EventArgs e)
{
// get pageid
string PagePath = "~" + Request.ServerVariables["URL"];
string PageType = Request.QueryString["filetype"];
//
XElement el = XElement.Load(Server.MapPath("~/xml/dotnettemplate.sitemap"));
//
var node = (from sitemap in el.Descendants()
where sitemap.Attribute("url").Value == PagePath
select sitemap.Attribute("pageid").Value).SingleOrDefault();
//
string pageid = string.Format("{0}", node);
Response.Write(pageid);
}
It def works (the response.write executes fine) and even if I change it to string pageid = "1"; it still doesn't work.
Any ideas?
Thanks, Kx
replace
<link href="/dotnettemplate/style/style.ashx?pageid=<%=pageid%>" rel="stylesheet" type="text/css" />
<asp:Literal ID="litStylesheet" runat="server" />
and then replace
Response.Write(pageid);
litStylesheet.Text = String.Format("<link href='/dotnettemplate/style/style.ashx?pageid={0}' rel='stylesheet' type='text/css' />", pageid);
Also, for a simple string conversion, you do not need to use a String.Format, the following will suffice:
string pageid = node.ToString();
string pageid = (from sitemap in el.Descendants()
where sitemap.Attribute("url").Value == PagePath
select sitemap.Attribute("pageid").Value).SingleOrDefault().ToString();
public string pageid; above the Page_Load event (even though that was where the value was assigned) I could use it in the .aspx file.
Thanks for your help tho, I am going to use the method you suggested for loading in the style.ashx