Authorization methodologies to help prevent attacks: The JavaScript should be placed under the .NET Common Language Runtime (CLR) managed code control by injecting the script with the ClientScript class into the HTML markup code sent to the client browser.
#region Print Grid
//---------------------------------------------------------------------------
/// <summary>
/// Method Name: GenerateDisplayPrintDialogScript
/// Description: Loads javascript to perform printing of grid.
/// </summary>
//---------------------------------------------------------------------------
public void GenerateDisplayPrintDialogScript()
{
string jScript = string.Empty;
jScript = "<script language='javascript' type='text/javascript'>function Print(ddl)" +
"{ " +
" if (ddl.selectedIndex == 1) " +
" {" +
" PagingGridView1.print(); " +
" ResetDDL(); " +
" } " +
" else if (ddl.selectedIndex == 2)" +
" { " +
" PagingGridView1.exportToExcel('UserList', true, true, false, true);" +
" } " +
" else if (ddl.selectedIndex == 3)" +
" { " +
" PagingGridView1.exportToWord('UserList', true, true, false, true);" +
" } " +
"} " +
"</script>";
if (!ClientScript.IsClientScriptBlockRegistered("PrintScript"))
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "PrintScript", jScript);
}
}
//---------------------------------------------------------------------------
/// <summary>
/// Method Name: GenerateResetDDLScript
/// Description: Resets the DDL back to the zero index when action completed.
/// </summary>
//---------------------------------------------------------------------------
public void GenerateResetDDLScript()
{
string jScript = string.Empty;
jScript = "<script language='javascript' type='text/javascript'>function ResetDDL()" +
"{ " +
" document.getElementById('" + this.ddlActions.ClientID + "').selectedIndex = 0; " +
"}" +
"</script>";
if (!ClientScript.IsClientScriptBlockRegistered("ResetDDLScript"))
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "ResetDDLScript", jScript);
}
}
#endregion Print Grid
The Client Script Manager Class (ClientScript) can also be utilized to register JavaScript files in the same manner as the script strings above. The advantage of utilizing a JavaScript file is that breakpoints can be set in it to allow code debugging stop and restart breakpoints.