java script alert validation

Last post 05-18-2008 10:37 AM by NC01. 4 replies.

Sort Posts:

  • java script alert validation

    05-17-2008, 6:57 PM
    • Loading...
    • tjrey
    • Joined on 05-14-2008, 3:04 PM
    • Posts 11

     

    I am looking to add some client side validation to my project Smile. What i am looking to do is to have a javascript warning on click that will stop the current action if the users clicks no. 

    so far i have got the onclientclick but not 100% on the JS and if i need to return the value and so on.

     I am using asp.bet 2.0 with C sharp incase it makes any diffrence.

    Due to restrictions inplace i CAN NOT use the inbuild validation from the toolbox.

     

    thank you.
     

  • Re: java script alert validation

    05-17-2008, 8:08 PM
    • Loading...
    • emady
    • Joined on 05-12-2008, 12:08 PM
    • Sydney
    • Posts 196

    Hi there,

    there is a very simple way you can call a javascript method then in that method return true or false. true incase validation is correct and false when validation is incorrect then for onclick of your buttons (if they are html buttons) add onclick attribute and call your methods.

    Cheers,
    Emad Yazdanpanah
    From http://www.CSharpCourses.com
  • Re: java script alert validation

    05-17-2008, 8:15 PM
    • Loading...
    • tjrey
    • Joined on 05-14-2008, 3:04 PM
    • Posts 11

     ok could you please show me a code example

  • Re: java script alert validation

    05-18-2008, 4:27 AM
    • Loading...
    • emady
    • Joined on 05-12-2008, 12:08 PM
    • Sydney
    • Posts 196

    Hey My friend,

    this is the sample

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >

    <head runat="server">

    <title>Untitled Page</title>

    <script type="text/javascript" language="javascript">

    function CheckValidation()

    {

    if(document.getElementById('TextBox1').value =='')

    return false;

    else

    return true;

    }

    </script>

    </head>

    <body>

    <form id="form1" runat="server">

    <div>

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

     

    </div>

    <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick= "return CheckValidation( )" OnClick="Button1_Click" />

    </form>

    </body>

    </html>

     

    I hope that help!

     

    Cheers,
    Emad Yazdanpanah
    From http://www.CSharpCourses.com
  • Re: java script alert validation

    05-18-2008, 10:37 AM
    Answer
    • Loading...
    • NC01
    • Joined on 08-26-2005, 3:33 PM
    • Posts 8,724

    I think that he is looking for something more like this:

    <script type="text/javascript" language="javascript">
    function checkValidation()
    {
     if(document.getElementById('<%= TextBox1.ClientID %>').value =='')
     {
      return window.confirm('Are you sure?');
     }
     else
     {
      return true;
     }
    }
    </script>

    NC...

Page 1 of 1 (5 items)
Microsoft Communities
Page view counter