Click here to Skip to main content
15,895,935 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: IErrorInfo.GetDescription failed with E_FAIL(0x80004005) Pin
Jay Royall19-Oct-12 3:12
Jay Royall19-Oct-12 3:12 
Questionweb stats recommendations Pin
Jassim Rahma19-Oct-12 2:52
Jassim Rahma19-Oct-12 2:52 
AnswerRe: web stats recommendations Pin
code-frog19-Oct-12 18:11
professionalcode-frog19-Oct-12 18:11 
Questionhow can i add two page route in mvc? Pin
mhd.sbt19-Oct-12 2:32
mhd.sbt19-Oct-12 2:32 
AnswerRe: how can i add two page route in mvc? Pin
Deflinek19-Oct-12 2:50
Deflinek19-Oct-12 2:50 
GeneralRe: how can i add two page route in mvc? Pin
mhd.sbt19-Oct-12 6:25
mhd.sbt19-Oct-12 6:25 
AnswerRe: how can i add two page route in mvc? Pin
Mayank_Gupta_24-Oct-12 22:51
professionalMayank_Gupta_24-Oct-12 22:51 
QuestionAjax page method call during form validation Pin
Jay Royall18-Oct-12 22:43
Jay Royall18-Oct-12 22:43 
Hi,

I have a registration form which consists of, amongst others, an email field. When the user enters their email address, the onChange event is fired and a server side page method is called which checks the email address and returns a boolean value. This works fine when invoked from the onChange event of the textbox.

The problem occurs when the submit button is clicked; the submit button invokes the Javascript validation function and posts back if the form is valid, however, because the email validation involves an AJAX server side call, the function isn't waiting for the response and so causes the form to be submitted regardless of the email validation result. I hope I have explained this adequately but if not I have included a cut down version of my page:

ASP.NET
<script type="text/javascript">

    var pageIsValid;
    var emailAddressMessage;

    function ValidateForm() {

        pageIsValid = true;

            PageMethods.EmailAddressIsValid(document.getElementById('<%= txtNewMemberEmailAddress.ClientID %>').value, ValidateEmailAddressSuccess, ValidateEmailAddressFailed);

        // other validation calls have been left out

        if (pageIsValid == false) {
                    alert('Some information is either missing or invalid.  Hover your mouse over the red crosses for more information');
            }

            return pageIsValid;
    }


        function ValidateEmailAddressSuccess(result) {
            if (result == false) {
                document.getElementById('<%= imgNewMemberEmailAddress.ClientID %>').src = "/Images/cross.png";

                emailAddressMessage = 'The email address you have entered is already in use';

                pageIsValid = false;
            }
            else {
                document.getElementById('<%= imgNewMemberEmailAddress.ClientID %>').src = "/Images/tick.png";

                emailAddressMessage = 'This field is valid';
            }
        }
        function ValidateEmailAddressFailed(result) {
            document.getElementById('<%= imgNewMemberEmailAddress.ClientID %>').src = "/Images/cross.png";

            alert(result.get_message());
        }

</script>

<asp:Button runat="server" ID="btnRegister" Text="Register" CssClass="button" OnClientClick='Javascript:return ValidateForm();' />


If anyone could suggest a better way of doing this it would be appreciated.

Thanks

Jay
AnswerRe: Ajax page method call during form validation Pin
Richard Deeming19-Oct-12 1:44
mveRichard Deeming19-Oct-12 1:44 
GeneralRe: Ajax page method call during form validation Pin
Jay Royall19-Oct-12 2:03
Jay Royall19-Oct-12 2:03 
GeneralRe: Ajax page method call during form validation Pin
BobJanova19-Oct-12 2:36
BobJanova19-Oct-12 2:36 
GeneralRe: Ajax page method call during form validation Pin
Richard Deeming19-Oct-12 8:03
mveRichard Deeming19-Oct-12 8:03 
AnswerRe: Ajax page method call during form validation Pin
BobJanova19-Oct-12 2:39
BobJanova19-Oct-12 2:39 
GeneralRe: Ajax page method call during form validation Pin
Jay Royall19-Oct-12 3:04
Jay Royall19-Oct-12 3:04 
AnswerRe: Ajax page method call during form validation Pin
jkirkerx19-Oct-12 10:08
professionaljkirkerx19-Oct-12 10:08 
Questionhow we can add source code in our running projects which given by code project website Pin
ashvin sharma18-Oct-12 22:40
ashvin sharma18-Oct-12 22:40 
AnswerRe: how we can add source code in our running projects which given by code project website Pin
Richard MacCutchan18-Oct-12 23:28
mveRichard MacCutchan18-Oct-12 23:28 
GeneralRe: how we can add source code in our running projects which given by code project website Pin
ashvin sharma19-Oct-12 1:52
ashvin sharma19-Oct-12 1:52 
GeneralRe: how we can add source code in our running projects which given by code project website Pin
Richard MacCutchan19-Oct-12 2:20
mveRichard MacCutchan19-Oct-12 2:20 
Questionhelp plx Pin
Muddassir Husain Awan18-Oct-12 20:35
Muddassir Husain Awan18-Oct-12 20:35 
AnswerRe: help plx Pin
Richard MacCutchan18-Oct-12 23:26
mveRichard MacCutchan18-Oct-12 23:26 
GeneralRe: help plx Pin
Pete O'Hanlon18-Oct-12 23:43
mvePete O'Hanlon18-Oct-12 23:43 
GeneralRe: help plx Pin
Richard MacCutchan19-Oct-12 0:09
mveRichard MacCutchan19-Oct-12 0:09 
GeneralRe: help plx Pin
jkirkerx19-Oct-12 10:37
professionaljkirkerx19-Oct-12 10:37 
AnswerRe: help plx Pin
J4amieC19-Oct-12 2:02
J4amieC19-Oct-12 2:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.