CodeCharge Studio | All ASP PHP Perl ColdFusion Java C#.NET VB.NET |
This example shows how to process critical errors. In this case, the error condition is based on the availability of an input parameter called task_id which is received over the URL.
In the first instance, we want to prevent the page from displaying if the input parameter is not received. We place code in the After Initialize event of the page to check for the input parameter and display an error message if no value is received for it.
Function Page_AfterInitialize(Sender) If IsEmpty(CCGetParam("task_id", Empty)) Then UnloadPage response.write("Error: ""task_id"" parameter is not specified.") response.end End If End Function
function Page_AfterInitialize(& $sender) { if (CCGetFromGet("task_id","") == "") { print ("Error: \"task_id\" parameter is not specified."); exit; } }
sub Page_AfterInitialize() { if (CCGetFromGet("task_id","") eq "") { if (!$isHTTPHeader) { print $page_header; print "Content-type: text/html\n\n"; } print "Error: \"task_id\" parameter is not specified.\n"; exit 0; } }
<!---Page_AfterInitialize ---> <CFMODULE Template="CCGetParam.cfm" strName="task_id"> <CFIF CCGetParam EQ ""> <CFOUTPUT>Error: "task_id" parameter is not specified.</CFOUTPUT> <CFEXIT> </CFIF>
'Page_AfterInitialize If IsNothing(Request.QueryString("task_id")) OR Request.QueryString("task_id") = "" Then Response.Write("Error: ""task_id"" parameter is not specified.") Response.[End] End If
//Page_AfterInitialize if (Request.QueryString["task_id"] == null || Request.QueryString["task_id"].Length == 0) { Response.Write("Error: 'task_id' parameter is not specified."); Response.End(); }
//Page_AfterInitialize if (StringUtils.isEmpty(e.getPage().getHttpGetParams().getParameter("task_id"))) { Utils.printFatalError("Error: \"task_id\" parameter is not specified.", e.getPage().getResponse()); }
In the second instance, we want to prevent a form called Tasks from displaying if the input parameter task_id is not received.
Function Page_AfterInitialize() If IsEmpty(CCGetParam("task_id", Empty)) Then Tasks.Visible=False Tasks_Error.Value="Error: ""task_id"" parameter is not specified." End If End Function
function Page_AfterInitialize() { global $Tasks; global $Tasks_Error; if (CCGetFromGet("task_id","") == "") { $Tasks->Visible = False; $Tasks_Error->SetValue("Error: \"task_id\" parameter is not specified."); } }
sub Page_AfterInitialize() { if (CCGetFromGet("task_id","") eq "") { $Tasks->{Visible} = 0; $Tasks_Error->SetValue("Error: \"task_id\" parameter is not specified."); } }
Set the Default Value property of the 'Task_Error' label to "Error: 'task_id' parameter is not specified."
<!---Page_AfterInitialize ---> <CFMODULE Template="CCGetParam.cfm" strName="task_id"> <CFIF CCGetParam EQ ""> <CFSET hideTasks=True> <CFELSE> <CFSET hideTasks_Error=True> </CFIF>
<!-- BEGIN Label Tasks_Error --> {Tasks_Error} <!-- END Label Tasks_Error -->
<!---Page_AfterInitialize ---> <CFMODULE Template="CCGetParam.cfm" strName="task_id"> <CFIF CCGetParam EQ ""> <CFSET hideTasks=True> <CFELSE> <CFSET hideTasks_Error=True> </CFIF>
//Page_AfterInitialize if (StringUtils.isEmpty(e.getPage().getHttpGetParams().getParameter("task_id"))) { e.getPage().getRecord("Tasks").setVisible(false); e.getPage().getControl("Tasks_Error").setValue("Error: \"task_id\" parameter is not specified."); }
'Page_AfterInitialize If IsNothing(Request.QueryString("task_id")) OR Request.QueryString("task_id") = "" Then TasksHolder.Visible=False Else Tasks_Error.Visible=False End If
//Page_AfterInitialize if (Request.QueryString["task_id"] == null || Request.QueryString["task_id"].Length == 0) { TasksHolder.Visible = false; } else { Tasks_Error.Visible = false; }