Click here to Skip to main content
15,908,768 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
How to open Popup window on button click after the server side validation.
Posted

use register.clientscript after server side validataion .
 
Share this answer
 
Comments
Robymon 6-Mar-12 4:04am    
Can i get the full format?
if you use register.clientscript the page need to be reloaded. Instead use webmethod to do serverside validation and show the popup accordingly depending on the validation. Here is the code

Default.aspx
HTML
<html>
<head>
 <script src="Scripts/jquery.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
    $(document).ready(function () {
        // Add the page method call as an onclick handler for the div.
        $("#Result").click(function () {
            alert("clicked");
            $.ajax({
                type: "POST",
                url: "Default.aspx/validate",
                data: "{'value':'"+$("#value").val()+"'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    // Replace the div's content with the page method's return.
                    if (msg.d == "true")
                    //write the code to show popup.
                        $("#value").val("THis is validated");
                    else
                    // dont show the popup.
                        $("#value").val("THis  is not validated");


                },
                error: function (err) {
                    debugger;
                }
            });
        });
    });
      


    </script>
  <input type="text" id="value" /> 
  <input type="submit" id="Result" />
</body>
</html></html>


Default.aspx.cs
C#
public partial class Default : System.Web.UI.Page
   {
       [WebMethod]
       public static string validate(string value)
       {
           if (value.Equals("showpopup"))
               return "true";
           else
               return "false";
       }
   }

Hope this answers your question
 
Share this answer
 
Try this, on button click event server side
C#
protected void btnOpenPopup_OnClick(object sender, EventArgs e)
    {
        ClientScript.RegisterStartupScript(Page.GetType(), "openPopUp", "javascript:openPopUp();", true); //In this way you can call any java script function any where in the code behind.
 
Share this answer
 
in .aspx page
function Popup()
{
window.open('Default2.aspx');
}

try this in button click event
//button click event
                    ScriptManager.RegisterStartupScript(Page, this.GetType(), "myscript", "javascript:Popup();", true);

or
//page load

            imgbutton.Attributes.Add("onclick", "javascript:window.open('Default2.aspx');");

or
//page load
imgmstrpkgNo.OnClientClick = "Popup();";
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900