This is an c# asp.net based environment running [webmethod] codebehind and PageMethods on the rendered page to make calls to the codebehind.
I use asp: type labels, textboxes, buttons and validators. I have several buttons which become visible at different points in a process. Also on the form are field validators (asp:RequiredFieldValidator), which fire when the Enter key is pressed or the "DefaultButton" is clicked. I want the validation to occur, however I want the DefaultButton to change so that the function which is fired is never executed again. That is, if the enter key is pressed, at any time, the DefaultButton (and associated OnClientClick event) is fired. I wish to change what the DefaultButton is using javascript.
On the form is:
<form id="form1" runat="server" DefaultButton="btnCreateAccount">
.
.
.
<asp:Button ID="btnCreateAccount" runat="server" Text="Signup" style="display: inherit;" OnClientClick="ValidEmailTest(); return false;"/>
<asp:Button ID="btnVerifyAccount" runat="server" Text="Verify Mail Account" style="display: none;" OnClientClick="TestSetup(); return false;"/>
<asp:Button ID="btnValidate" runat="server" Text="Check Verification Code" style="display: none;" OnClientClick="Validation(); return false;"/>
I believe that if I can change the value of DefaultButton to a different button, then when the newly exposed fields are populated and the Enter key is pressed, then the fields would be validated and that button's "OnClientClick" action is performed. I am looking for the value of "DefaultButton", or where it can be modified, so I know what can be changed.
I have tried:
xyz = document.getElementById('<%= form1.ClientID %>')..getdefaultbutton;
alert ("Default Button is: "+ xyz);
The results: "Default Button is: undefined"
xyz = document.getElementById('<%= form1.ClientID %>').getAttribute("DefaultButton");
alert ("Default Button is: "+ xyz);
The results: "Default Button is: null"
var xyz = document.getElementById('<%= form1.ClientID %>').getAttributeNames();
alert ("Attributes are: "+ xyz);
The results: "Attributes are: method,action,onkeypress,id"
I do not want a post or a call back as everything is running as pagemethods running in the codebehind async. and delivering results to the page. Any call or post back refreshes the page and resets what the page displays and values the user has entered, or the system has returned.
Suggestions?