Tuesday, June 19, 2007

The story of the client-side validation in ASP.NET

Just flushing out some materials right now. I just need to provide this story it to myself in first place, so I have no confusion what is the current model/sequence.

On the control:

<input type="submit" name="ctl00$DefaultContent$submitInsideGroupButton" value="Submit Inside Group!" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$DefaultContent$submitInsideGroupButton&quot;, &quot;&quot;, true, &quot;InsideGroup&quot;, &quot;&quot;, false, false))" id="ctl00_DefaultContent_submitInsideGroupButton" />

Webresources

function WebForm_PostBackOptions(eventTarget, eventArgument, validation, validationGroup, actionUrl, trackFocus, clientSubmit) {

this.eventTarget = eventTarget;

this.eventArgument = eventArgument;

this.validation = validation;

this.validationGroup = validationGroup;

this.actionUrl = actionUrl;

this.trackFocus = trackFocus;

this.clientSubmit = clientSubmit;

}

function WebForm_DoPostBackWithOptions(options) {

var validationResult = true;

if (options.validation) {

if (typeof(Page_ClientValidate) == 'function') {

validationResult = Page_ClientValidate(options.validationGroup);

}

}

if (validationResult) {

if ((typeof(options.actionUrl) != "undefined") && (options.actionUrl != null) && (options.actionUrl.length > 0)) {

theForm.action = options.actionUrl;

}

if (options.trackFocus) {

var lastFocus = theForm.elements["__LASTFOCUS"];

if ((typeof(lastFocus) != "undefined") && (lastFocus != null)) {

if (typeof(document.activeElement) == "undefined") {

lastFocus.value = options.eventTarget;

}

else {

var active = document.activeElement;

if ((typeof(active) != "undefined") && (active != null)) {

if ((typeof(active.id) != "undefined") && (active.id != null) && (active.id.length > 0)) {

lastFocus.value = active.id;

}

else if (typeof(active.name) != "undefined") {

lastFocus.value = active.name;

}

}

}

}

}

}

if (options.clientSubmit) {

__doPostBack(options.eventTarget, options.eventArgument);

}

}

function Page_ClientValidate(validationGroup) {

Page_InvalidControlToBeFocused = null;

if (typeof(Page_Validators) == "undefined") {

return true;

}

var i;

for (i = 0; i < Page_Validators.length; i++) {

ValidatorValidate(Page_Validators[i], validationGroup, null);

}

ValidatorUpdateIsValid();

ValidationSummaryOnSubmit(validationGroup);

Page_BlockSubmit = !Page_IsValid;

return Page_IsValid;

}

function ValidatorCommonOnSubmit() {

Page_InvalidControlToBeFocused = null;

var result = !Page_BlockSubmit;

if ((typeof(window.event) != "undefined") && (window.event != null)) {

window.event.returnValue = result;

}

Page_BlockSubmit = false;

return result;

}

Inline:

var Page_ValidationActive = false;

if (typeof(ValidatorOnLoad) == "function") {

ValidatorOnLoad();

}

function ValidatorOnSubmit() {

if (Page_ValidationActive) {

return ValidatorCommonOnSubmit();

}

else {

return true;

}

}

No comments: