Stop execution of a page
12,848
Don't do Response.End(). Just return without doing anything.
Author by
Kash
Updated on June 04, 2022Comments
-
Kash almost 2 years
I have a task board, some person is working on some task, if task is assigned to another person by his manager the first person who is working on the task board, his execution should be stopped, and a message should be displayed that "This task is assigned to some one else."
I tried using following in page load.
//Code Behind if (!Owner) { SomecontrolsToHide(); MessageDisplay(); // JavaScript function call using RegisterStartupScript() Response.End(); } protected void MessageDisplay() { string dbMessage = "Task is assigned to someone else."; ClientScriptManager cs = Page.ClientScript; cs.RegisterStartupScript(typeof(Page), "ShowMessageWrapup_" + UniqueID, "showMessageDisplay('','" + dbMessage + "');", true); }
// JavaScript function that displays message. function showMessageDisplay(args, displayMessage) { if (displayMessage != "") { document.getElementById("spanMessage").innerHTML = displayMessage; document.getElementById("spanMessage").style.display = 'inline'; } }
It stops the execution but message is not displayed and Controls are not hidden too.
What should I do?
-
Kash over 12 yearshow, as i have different events on the page. for example user clicked a button, then how can i return without executing button's click event.
-
Piotr Perak over 12 yearsThat's where you should put if (!Owner).
-
Kash over 12 yearsyou mean like if(!Owner) { return; }
-
Kash over 12 yearsreturn will just return from page_load event but button's click event will still fire.
-
Piotr Perak over 12 yearsif you do sth on button click that's where you should do what should be done - in btn click handler. Not in page_load. In click handler you check if (!Ownher) and hide controls and return.
-
Kash over 12 yearsI have multiple events on page, then I need to check (!Owner) condition in every event. I want to avoid that, so I want to do that in page_load.
-
Piotr Perak over 12 yearsYou should put logic in one place.