My routing/path breaks when I add.....

Posted by Carpenter under Regular Expressions on 11/2/2009 | Views : 2611 | Status : [Member] | Replies : 6
Hi

My routing/path breaks when I add <asp:Literal id="ClassToUse" runat="server"/>

So I have the below (working bit of code) in my MasterPage so as to be able to link to the Default.aspx etc, page from any page... and it was working if I was also a few folders deep into the site - but it doesn't seem to at prescent - after adding the "<asp:Literal ID="ClassToUse" runat="server"/>" bit...

The dynamic css ClassToUse worked on it own too, but when I mix them up I cause problems (an "/~/" is added to my link's path (http://localhost:port/root_folder/~/file) at root level, and for 1 folder deep into the site also I get http://localhost:port/root_folder/subfolder/~/file).

Working:

<li><a id="home_link" href= "~/Default.aspx" title="Home" onfocus="this.blur();" runat="server">Home</a></li>


Not working:

<li><a <asp:Literal id="ClassToUse" runat="server"/> id="home_link" href= "~/Default.aspx" title="Home" onfocus="this.blur();" runat="server">Home</a></li>



I am also getting an "Element a is missing the > from its start tag" valadation warning, when I hover over a green squigle under the opening a tag.
Everyting after the <asp:Literal ID="ClassToUse" runat="server"/> is showing up in black also...

Any help on getting both bits to work together - the path from root folder and the dyanmic css style?




Responses

Posted by: Lakhangarg on: 11/2/2009 [Member] [Moderator] Silver

Up
0
Down
Hi Carpenter-
Not working:
<li><a <asp:Literal id="ClassToUse" runat="server"/> id="home_link" href= "~/Default.aspx" title="Home" onfocus="this.blur();" runat="server">Home</a></li>



Check the above code your are adding literal control in anchor tag and that is not possible.
use can use like this:

<li><a id="home_link" href= "~/Default.aspx" title="Home" onfocus="this.blur();" runat="server"><asp:Literal id="ClassToUse" runat="server"/>Home</a></li>



if your purpose to use literal is to implement css then use like this:

<li><a id="home_link" href= "~/Default.aspx" title="Home" onfocus="this.blur();" runat="server" class="ClassToUse">Home</a></li>



Thanks & Regards
Lakhan Pal Garg

Carpenter, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Carpenter on: 11/3/2009 [Member] Starter

Up
0
Down
Hi Lakhangarg - thanks for the reply/help. My purpose is to use literal to implement css - but to have it vary depending on the page I'm on, the css being applied to the "a" tag too.

That bit though seems to be working for me at present for some reason, but it breaks my "use of ~/ within links" - they only work for me now when I'm in the root folder - and don't work when I'm within sub folders...


Do you know if there are any consiquenses of using the below but limiting my pages to the root folder - as it does seem to be working there atleast:

<li><a <asp:Literal id="ClassToUse" runat="server"/> id="home_link" href= "Default.aspx" title="Home" onfocus="this.blur();" runat="server">Home</a></li>



Carpenter, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lakhangarg on: 11/3/2009 [Member] [Moderator] Silver

Up
0
Down
<li><a <asp:Literal id="ClassToUse" runat="server"/> id="home_link" href= "Default.aspx" title="Home" onfocus="this.blur();" runat="server">Home</a></li>

This is not the way to implement Css
if your CSS class change according to some condition then use can use protected variable in .cs page and use as:
<li><a id="home_link" href= "~/Default.aspx" title="Home" onfocus="this.blur();" runat="server" class='<% = CSSName%>'>Home</a></li>

Where CSSName is a Protected varibale.

Thanks & Regards
Lakhan Pal Garg


Carpenter, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Carpenter on: 11/3/2009 [Member] Starter

Up
0
Down
Hi again

You say "use can use protected variable in .cs ", could you tell me how to as I do not understand that bit... I use vb code like the below to update the literal at present..


Select Case filename
Case "Default.aspx"
' switch the background pics in the li/as
ClassToUse.Text = "class=" + """" + "active" + """"



How would I go about getting the "class=" + """" + "active" + """" into the <% = CSSName%> in your:

<li><a id="home_link" href= "~/Default.aspx" title="Home" onfocus="this.blur();" runat="server" class='<% = CSSName%>'>Home</a></li>








Carpenter, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lakhangarg on: 11/3/2009 [Member] [Moderator] Silver

Up
0
Down
Hi-

Declare a Variable in the Class file with protected or Public modifier.. as we can do like this in C#
protected string ClassName="active";

Select Case filename

Case "Default.aspx"
ClassName="active"
Case "Second.aspx"
ClassName="disable"



Thanks & Regards
Lakhan Pal Garg

Carpenter, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Carpenter on: 11/3/2009 [Member] Starter

Up
0
Down
Thanks for the help again Lakhangarg - but this got both working together for me in the end... Went "You beauty" when it worked :)


<li><asp:Hyperlink id="ClassToUse" runat="server" NavigateUrl="~/Default.aspx" title="Home" onfocus="this.blur();">Home</asp:Hyperlink></li>



Case "Default.aspx"
' switch the background pics for the li
ClassToUse.CssClass = "active"

Carpenter, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response