English 中文(简体)
B. 拦截控制使之失效的最佳途径
原标题:Best way to intercept control rendering
  • 时间:2011-01-13 11:59:23
  •  标签:
  • asp.net

我在我们的海关管理系统中使用了控制,我们没有这方面的源码,我想做的是改变这一控制的成果。

现在,我可以在我的基页表中检查,如果控制在网页上使用,然后改变需要改变的html,但这似乎比仅仅1次使用过度。

因此,没有来源法,是否还有其他改变控制行为的方法? 我的想法不像上文所述的方式。

增 编

最佳回答

在习俗控制下进行治疗:

public class MyCMSControl: CommercialCMSControl
{
    protected override void Render(HtmlTextWriter writer)
    {
        StringBuilder stringBuilder = new StringBuilder();
        StringWriter stringWriter = new StringWriter(stringBuilder );

        using (HtmlTextWriter myWriter = new HtmlTextWriter(stringWriter ))
        {
            base.Render(myWriter);

            string newOutput;
            // the original output is in stringBuilder, do whatever you want, and
            // put it in newOutput


            writer.Write(newOutput);
        }
    }
}

如果你想能够操纵该页具体编码中的产出,就添加一个活动,例如:

public delegate void OnRenderHandler(object sender, string originalOutput, HtmlTextWriter writer)
public OnRenderHandler OnRender;
...
/// before writer.Write above...
if (OnRender!=null) {
    OnRender(this,stringBuilder.ToString(),writer);
}

为了在设计师中提供您的习惯版本,你需要网上查阅。

<pages>
  <controls>
    <add namespace="My.Control.Namespace" assembly="My.Control.Assembly" tagPrefix="MyControlsPrefix"/>
  </controls>
</pages>
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签