Hello, I did several searches, yet still not found a solution to how do we do server side validation in Settings page.
Anyone could shed some light on how could I stop the page from redirecting to the Home page when I click Update.
When I encounter invalid settings (which must be checked from server side), I want to display some messages but the page keep redirecting.
For client side validation, I tried to do something like this
<script language="javascript" type="text/javascript">
function isValid()
{
// Some logic here and return true/false accordingly.
// The checking logic is slightly
}
</script>
On server side I tried to inject javascript to the CommandButton cmdUpdate like this
var cmdUpdate = this.Parent.TemplateControl.FindControl("cmdUpdate") as CommandButton;
if (cmdUpdate != null) cmdUpdate.Attributes.Add("onclick", " if (!isValid()) return false;");
but no luck.
When I view source code. the javascript "if" statement is injected in "onclick" event of the "<span>" element of the CommandButton. But the postback of the button is in the "onclick" event of the "<input>" element inside so it seems like the onclick of the <span> overrides the onclick of the <input>????.
For e.g <span onclick="...."><input onclick="...">.....</input></span> <-- this is how the CommandButton is generated on the client.
Thanks everyone for your time reading this and excuse my broken English.
:(
Regards
Alex To