任何方式prevent母版页更改元素ID? [英] Any way to prevent master pages from changing element IDs?
问题描述
我期待在添加母版页到现有的网站,但已经发现,一旦我做了元素的ID的获取与code ppended $ P $(如 ctl00_MainPageContent _
)。
I'm looking at adding master pages to an existing site but have found that once I do, the elements' IDs get prepended with a code (e.g. ctl00_MainPageContent_
).
Unforunately,这打破了使用原始,未经修改的元素ID在页面上现有的脚本。
Unforunately, this breaks existing scripts on the page that use the original, unmodified element ID.
我知道我可以用&LT更换;%= Element.ClientID%方式>
,但它会是真棒,如果我可以完全禁用此行为
I realize that I can replace it with <%= Element.ClientID %>
but it'd be awesome if I could disable this behavior altogether.
所以,我可以保持原有标识?
So, can I keep the original IDs?
推荐答案
这个问题已经回答了在previous后: <一个href=\"http://stackoverflow.com/questions/827723/remove-ctl00contentbody-from-rendered-control-id\">Remove母版生成的ID
The question was already answered in the previous post: Remove MasterPage Generated ID
该解决方案将覆盖渲染具有以下code事件:
The solution overrides the Render Event with the following code:
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
Dim Html As New StringWriter()
Dim Render As New HtmlTextWriter(Html)
MyBase.Render(Render)
writer.Write(Html.ToString().Replace("name=""ctl00$ContentBody$", _
"name=""").Replace("id=""ctl00_ContentBody_", "id="""))
End Sub
这篇关于任何方式prevent母版页更改元素ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!