Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0 ASP.NET
How to open Popup window on button click after the server side validation.
Posted 5-Mar-12 22:58pm
Robymon1.2K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

use register.clientscript after server side validataion .
  Permalink  
Comments
Robymon at 6-Mar-12 4:04am
   
Can i get the full format?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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>
<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
 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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Try this, on button click event server side
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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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();";
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 490
1 Maciej Los 305
2 Richard MacCutchan 270
3 Mathew Soji 220
4 BillWoodruff 210
0 OriginalGriff 8,834
1 Sergey Alexandrovich Kryukov 7,477
2 DamithSL 5,689
3 Maciej Los 5,329
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web03 | 2.8.1411028.1 | Last Updated 22 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100