How To Validate A Page On The Client Using Javascript



TODO:

Have you ever wanted to validate a page on the client side?

 

SOLUTION:

if (Page_ClientValidate("vgForgotPassword")) {
//do something
}

 

NOTES:

If the validation group does not have a name use ""

 

How To Display A Confirmation Dialog And Cancel The Postback When Using A Telerik RadButton



TODO:

You are using a Telerik RadButton, and you want to display a Confirm Dialog, and capture the user pressing cancel, thus canceling the Postback.

 

SOLUTION:

    <!-- Define button, and put method to call in the OnClientClicking event -->

    <telerik:RadButtonID="btnDelete"runat="server"Text="Delete Customer"OnClick="btnDelete_Click"

        OnClientClicking="ConfirmDelete">

    </telerik:RadButton>

   

    <!-- Confirm action here.  Cancel press in this dialog will return FALSE, which in turn we will catch and set cancel = true in the args -->

    <telerik:RadCodeBlockID="RadCodeBlock1"runat="server">

        <scripttype="text/javascript">

            function ConfirmDelete(sender, args) {

                if (!confirm('Delete Customer, do you wish to proceed?')) {

                    args.set_cancel(true);

                }

            }

        </script>

 

    </telerik:RadCodeBlock>

 

NOTES:

You may not need the RadCodeBlock, I did in this case due to Application

How To Execute Javascript Before Async Postback



TODO:

Have you ever wanted to execute some javascript before an async postback?  Place the below code in your aspx file, just under the Main Content Placeholder, or body tag if you are not using a master page.

 

SOLUTION:

     <script type="text/javascript">
          
          //add the init activity
          Sys.Application.add_init(appl_init);

          //Do this on init
          function appl_init() {
               var pagegReqManager = Sys.WebForms.PageRequestManager.getInstance();
               pagegReqManager.add_beginRequest(BeginHandler);
          }

          //Called before async postback
          function BeginHandler() {
               MyJavascriptMethod();
               MyOtherJavascriptMethod();
          }      
     </script>

 

NOTES:

There are no notes on this topic

How To Execute Javascript After Async Postback



TODO:

Have you ever wanted to execute some javascript after an async postback?  Place the below code in your aspx file, just under the Main Content Placeholder, or body tag if you are not using a master page.

 

SOLUTION:

     <script type="text/javascript">
          
          //add the init activity
          Sys.Application.add_init(appl_init);

          //Do this on init
          function appl_init() {
               var pagegReqManager = Sys.WebForms.PageRequestManager.getInstance();
               pagegReqManager.add_endRequest(EndHandler);
          }

          //Called after async postback
          function EndHandler() {
               MyJavascriptMethod();
               MyOtherJavascriptMethod();
          }      
     </script>

 

NOTES:

There are no notes on this topic