从呈现的控件ID中删除ctl00 $ ContentBody $ [英] Remove ctl00$ContentBody$ from rendered control ID

查看:236
本文介绍了从呈现的控件ID中删除ctl00 $ ContentBody $的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对以前只是纯HTML和Javascript的现有应用程序进行了一些更改.为了添加服务器端功能,我选择了ASP.NET,并利用了母版页"概念.不幸的是,在一个巨大的Web表单上,所有控件ID都以"ctl00 $ ContentBody $"为前缀.我在所有INPUT控件上添加了runat ="server",这是更改ID的原因.现在ID已更改,Javascript(写得很差我什至无法阅读,而且我对JS相当有经验)都已完全损坏.

I made some changes to an existing application that was previously just straight HTML and Javascript. To add server-side functionality, I chose ASP.NET, and took advantage of the Master Page concept. Unfortunately, on one huge web form, the control IDs are all mangled with the "ctl00$ContentBody$" prefix. I tacked a runat="server" on all the INPUT controls which is what altered the IDs. Now that the IDs have been changed, the Javascript (which is so poorly written I can't even read it, and I'm quite experienced with JS) is completely broken.

那么,如何防止这种废话被渲染到HTML中呢?我希望能够以某种方式创建一个继承HtmlGenericControl的类(我没有使用Web控件,我只是将runat ="server"附加到每个输入标签上),并且以某种方式覆盖了将该容器ID"粘贴在此处的逻辑ID和NAME属性的开头.然后,我可以在web.config中使用tagMapping进行全局更改.这可能吗?

So, how can I prevent this nonsense from being rendered into the HTML? I was hoping to somehow be able to create a class that inherits HtmlGenericControl (I am not using Web controls, I just tacked on a runat="server" to every input tag) and somehow override the logic that sticks this "container id" at the beginning of the ID and NAME attributes. Then I could use tagMapping in web.config to make the global change. Is this possible?

推荐答案

伙计们,我需要快速又肮脏的东西.多亏了HBoss,我得以提出一个非常简单的解决方案.在相关页面的代码后面,我刚刚添加了此子例程...

Quick and dirty was what I needed, folks. And thanks to HBoss I was able to come up with a very simple solution. On the code-behind of the page in question, I just added this subroutine...

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

这篇关于从呈现的控件ID中删除ctl00 $ ContentBody $的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆