开发者

What is the most efficient way of changing content before render (ASP.Net)

We are using a CMS and I need to alter correct some of the HTML that is being generated by a control that is completely black-boxed. Usually I would sub-class the offending control and tweak it w开发者_Python百科ithin that, but because of the way the control has been written I am unable to remove the offending attribute.

This leaves me the only option of performing this operation through the Render method on the master page itself. I was thinking of changing the content string before it is rendered, this would involve a bit of Regex in a bid to remove the invalid attribute being rendered.

Given that this operation will run on every page, is this the most efficient way of achieving it? Should I perhaps do a string.Contains() to check for the existance of the HTML element first? Is using Regex for this going to cause performance issues?


First, does this have to run on every page? If so, that is fine, but if you are merely running on every page because it is the solution you have currently in your mind, then it might be better to go back to the business problem at hand.

If you want an architectural decision, "fix before binding" is preferable to "fix in a rendering method". This is regardless of master page or not. I would rather massage a "data set" to using row binding events, as the code shows clearer intent and usually performs better.

I would also consider caching if this is the same content over and over again. If it is not, then why are you using the master page. And "it has a render event" is not a good reason.

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜