Hi,
I copied a function to print out any control passed into it, however it uses Response.Write which after doing some research i discovered it is not compatible with Ajax update panels, i researched some more and discovered that you should now use registerclientscriptblock, however i am unsure as to what the syntax should be, i have copied the code i have below, hopefully i havent been too naieve and it is actually possible to get the function to work this way, any help would be massivley appreciated.
thanks
Public Shared Sub PrintWebControl(ByVal ctrl As Control, ByVal Script As String)
Dim stringWrite As StringWriter = New StringWriter()
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(stringWrite)
If TypeOf ctrl Is WebControl Then
Dim w As Unit = New Unit(100, UnitType.Percentage)
CType(ctrl, WebControl).Width = w
End If
Dim pg As Page = New Page()
pg.EnableEventValidation = False
If Script <> String.Empty Then
pg.ClientScript.RegisterStartupScript(pg.GetType(), "PrintJavaScript", Script)
End If
Dim frm As HtmlForm = New HtmlForm()
pg.Controls.Add(frm)
Dim lbl As New Label
frm.Attributes.Add("runat", "server")
frm.Controls.Add(ctrl)
pg.DesignerInitialize()
pg.RenderControl(htmlWrite)
Dim strHTML As String = stringWrite.ToString()
lbl.Text = strHTML
pg.Controls.Add(lbl)
'this is where i replaced response.write("<Script>window.print.</script>")
pg.ClientScript.RegisterClientScriptBlock(pg.GetType(), "PrintJavaScript", "<script>window.print();</script>")
I copied a function to print out any control passed into it, however it uses Response.Write which after doing some research i discovered it is not compatible with Ajax update panels, i researched some more and discovered that you should now use registerclientscriptblock, however i am unsure as to what the syntax should be, i have copied the code i have below, hopefully i havent been too naieve and it is actually possible to get the function to work this way, any help would be massivley appreciated.
thanks
Public Shared Sub PrintWebControl(ByVal ctrl As Control, ByVal Script As String)
Dim stringWrite As StringWriter = New StringWriter()
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(stringWrite)
If TypeOf ctrl Is WebControl Then
Dim w As Unit = New Unit(100, UnitType.Percentage)
CType(ctrl, WebControl).Width = w
End If
Dim pg As Page = New Page()
pg.EnableEventValidation = False
If Script <> String.Empty Then
pg.ClientScript.RegisterStartupScript(pg.GetType(), "PrintJavaScript", Script)
End If
Dim frm As HtmlForm = New HtmlForm()
pg.Controls.Add(frm)
Dim lbl As New Label
frm.Attributes.Add("runat", "server")
frm.Controls.Add(ctrl)
pg.DesignerInitialize()
pg.RenderControl(htmlWrite)
Dim strHTML As String = stringWrite.ToString()
lbl.Text = strHTML
pg.Controls.Add(lbl)
'this is where i replaced response.write("<Script>window.print.</script>")
pg.ClientScript.RegisterClientScriptBlock(pg.GetType(), "PrintJavaScript", "<script>window.print();</script>")