如何避免添加RUNAT =&QUOT;服务器&QUOT;毁了我的服务器标签&LT;%...%GT; [英] How to avoid Adding runat="server" destroying my server tags <%...%>
问题描述
结果
我有几个℃的母版;李&GT;菜单,因为我必须设置类=选择当前页面中,我使用一个小的服务器标记找到的网址,并指定特定的类。
I have a masterpage with a few <li> for menu and since I have to set class=selected for the current page, I am using a little server tag to find the url and assign the particular class.
我有共10 LT;李&GT;而不是所有的菜单是提供给所有类型的用户,我需要切换少数的&lt的;李&GT;如果用户不是管理员,所以我=服务器加入到他们,所以我可以设置自己可见=通过C#假
I have total of 10 <li> and not all menu is available to all types of user, I need to toggle few of the <li> if the user is not admin, so I have runat="server" added to them so I can set their visible=false through c#
下面是它是如何一目了然:
Here is how it is at a glance:
<li runat="server" id="liBlog" class='<%= Request.Url.AbsoluteUri.EndsWith("/Blog") ? "selected" : "" %>'><a href="/Blog">Group Blog</a></li>
<li runat="server" id="liPoll" class='<%= Request.Url.AbsoluteUri.EndsWith("/Poll") ? "selected" : "" %>'><a href="/Poll">Poll</a></li>
<li id="liInvite" class='<%= Request.Url.AbsoluteUri.EndsWith("/Invite") ? "selected" : "" %>'><a href="/Invite">Invite</a></li>
<li id="liFavourite" class='<%= Request.Url.AbsoluteUri.Contains("/Favourite") ? "selected" : "" %>'><a href="/Favourite">My Favourites</a></li>
在&lt;立GT;无=服务器工作得很好,当正确的页面上的源$ C $ C类显示=选择或类=在适当情况下与其他LT;李&GT;用于工作也没关系,直到我决定添加=服务器。
The <li> without runat="server" works fine, when on correct page the source code shows class="selected" or class="" as appropriate, the other <li> used to work fine too, until I decided to add the runat="server".
在我补充说=服务器,阶级的整块=被发送到HTML页面,它不处理在所有服务器变量!我右键点击html和查看源代码,它被呈现为:
Once I added that runat="server", the whole block of class="" is being sent out to the html page, its not processing the server tags at all! I right click on the html and look at the source, it's being rendered as:
<li id="ctl00_ctl00_ContentPlaceHolder1_liBlog" class="<%= Request.Url.AbsoluteUri.EndsWith("/Blog") ? "selected" : "" %>"><a href="/Blog">Group Blog</a></li>
它浇在我的服务器标签到源$ C $ C!
It's pouring out my server tags into the source code!
为什么这种行为见过?我怎样才能避免呢?
Why is this behaviour seen? How can I avoid it?
我抬头了很多类似的线程在这里和那里几乎没有在谷歌,所以使这个,我不认为这是一个重复的问题。
I looked up a lot of similar threads in here and there was nearly nothing in google, so made this, I dont think this is a duplicate question.
推荐答案
您无法使用&LT;%=%&GT;
标签的属性里面的语法对他们的 =服务器
属性。
You can't use the <%= %>
syntax inside the properties of tags that have the runat="server"
attribute on them.
您要么需要:
- 通过您的$ C $设置属性C-背后
- 创建一个前pression构建器(和的第2部分和的第3部分),并使用
&LT;%$%&GT;
语法(注:这些链接的东西,我写上的我的的博客,因此,谨防自我链接=)
- Set the properties via your code-behind
- Create an Expression Builder (and part 2 and part 3) and use the
<%$ %>
syntax (note: these are links to stuff I wrote on my blog, so, beware the self link =)
这篇关于如何避免添加RUNAT =&QUOT;服务器&QUOT;毁了我的服务器标签&LT;%...%GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!