Question

I am trying to render a Wizard control to a HTML string on the click of a Button (using Control.Render). I am already disabling event validation with the following, which works fine and enables me to render the entire Page to the string. I do this within the user control that contains the Wizard:

protected void Page_Init(object sender, EventArgs e)
{
    if (Request.Form["__EVENTTARGET"] != null
        && Request.Form["__EVENTTARGET"] == btnPrint.ClientID.Replace("_", "$"))
    {
        Page.EnableEventValidation = false;
    }
}

While this works, I'd like to render the Wizard control on its own. I understand that I can override Page.VerifyRenderingInServerForm in order to prevent the page from throwing an exception when I attempt to render this control on its own (without runat="server" form tags), like so:

public override void VerifyRenderingInServerForm(Control control)
{
    // base.VerifyRenderingInServerForm(control);
}

However, I don't want to override this completely. Is there a way I can bypass this dynamically, either:

  • For the specific PostBack in which the button in question is clicked, or...
  • Specifically for the Wizard control?
Was it helpful?

Solution

How about something like:

public override void VerifyRenderingInServerForm(Control control)
{
    if (!SkipVerifyRenderingInServerForm)
    {
        base.VerifyRenderingInServerForm(control);
    }
}

public bool SkipVerifyRenderingInServerForm
{
    get
    {
        object o = HttpContext.Current.Items["SkipVerifyRenderingInServerForm"];
        return (o == null) ? false : (bool) o;
    }
    set
    {
        HttpContext.Current.Items["SkipVerifyRenderingInServerForm"] = value;
    }
}

You could then set SkipVerifyRenderingInServerForm to true in your button click event handler.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top