Hi Axel,
Thanks for the update.
For the first part about LinkButton, based on my test, if the form has a
defaultButton set, focus on a LinkButton and press ENTER will still make
the defaultButton to submit the form. Also, if you set the defaultButton
attribute of the form to a LinkButton, it also works. I'm not sure if I
fully understood your question here, would you please elaborate more?
For the second part of the question, do you mean that you want to execute
some custom javascript code after the page's client-side validation passes?
I'm afraid it will not be easy to do so. Let's take a look at the
javascript generated by ASP.NET (view the webform in IE and save it as a
complete static html page to get the javascript files):
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);
}
}
<A
id=LinkButton1
href='javascript:WebForm_DoPostBackWithOptions(new
WebForm_PostBackOptions("LinkButton1", "", true, "", "", false,
true))'>LinkButton</A>
As you can see, the validation and the postback steps are currently
executed in a single javascript function WebForm_DoPostBackWithOptions. You
might want to replace the __doPostBack function to do your own stuff but I
haven't tested this. The default __doPostBack implementation is generated
in the webform as:
<SCRIPT type=text/javascript>
<!--
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</SCRIPT>
Regards,
Walter Wang (
[email protected], remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.