Search code examples
printingaspwizard

Print all steps of asp:Wizard control


I have a asp:Wizard control in my Web Application.I need to be able to print at any step within the wizard , and print all steps up to that step not just the current step.

I've added a print button to every step page , and tried to call the javascript:window.Print(), but only the current step gets printed.

How do i get all the steps to print in 1 page?

i'd like to try and get this working in javascript first before i go down the PDF route . I've tried doing somehting like this :

protected void Page_Load(object sender, EventArgs e) 
    { 
        StringWriter sw = new StringWriter(); 
        HtmlTextWriter tw = new HtmlTextWriter(sw); 
        this.WizardStep2.RenderControl(tw); 
        string wizardHtmlContent = sw.ToString().Replace("\r\n", ""); 

        string printScript = @"function printDiv(printpage) 
                                { 
                                var headstr = '<html><head><title></title></head><body>'; 
                                var footstr = '</body>'; 
                                var newstr = printpage; 
                                var oldstr = document.body.innerHTML; 
                                document.body.innerHTML = headstr+newstr+footstr; 
                                window.print();  
                                document.body.innerHTML = oldstr; 
                                return false; 
                                }"; 


        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "PrentDiv", printScript, true); 
        this.Button1.Attributes.Add("onclick", "printDiv('" + wizardHtmlContent + "');"); 

    }

and for the aspx:

<form id="form1" runat="server"> 
<div> 
     <asp:Wizard ID="Wizard1" runat="server"> 
        <WizardSteps> 
            <asp:WizardStep ID="WizardStep1" runat="server" Title="Step 1"> 
                step1 
            </asp:WizardStep> 
            <asp:WizardStep ID="WizardStep2" runat="server" Title="Step 2"> 
                step2 
            </asp:WizardStep> 
        </WizardSteps> 
    </asp:Wizard> 
    <asp:Button ID="Button1" runat="server" Text="Button" /> 
</div> 
</form>

But i'm getting a missing runat=server error on line 3 , when i attempt to render the wizard control , so i think i may need to create a new window, then output the string before i print it , but cant seem to get that working ...Anyone any ideas ?


Solution

  • i have found a solution for my problem , i didnt manage to accomplish it client side , but ive managed to solve it server side which is better than going down the PDF route which i didnt want to do. I found a great article here : Printing in ASP.NET

    which i ammended to print all steps of my wizard control in one go. thanks for all your help.