Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to show a .aspx page in a pop up window on button click event . I am able to display images in pop up window but how to display a server side page like .aspx.
Posted

First of all, please kiss away the thought of using any of the default or built-in pop up windows for doing this, such as alert dialog boxes etc.

If you want to show a pop-up window, you create one using a simple HTML container element, which is a simple div element. Now, the code to load that page is pretty much simple, you would use a simple Ajax request to request for the data. You're not concerned with any of the C# code here, you just want to render the HTML document here. So, create a HTML web-page as this one (I am going to write the code for pop-up window only),

HTML
<div class="pop-up" style="display: none;">
   <!-- Leave it empty -->
</div>


.. you can add other styles to make it float over other elements too. Now, write the JavaScript code to create a new Ajax request and call for data. Like this,

JavaScript
// I will use jQuery here..
$(document).ready(function () {
   // create the request here, 
   $.ajax({
      url: 'link-of-page-to-download',
      success: function (data) {
         /* upon success, 
          * chances are that entire HTML will be passed down, 
          * do not worry about any return statements, the document will be sent
          * down into the data variable here.. 
          */
         $('.pop-up').html(data);
         // Show the pop up, 
         $('.pop-up').show();
      }
   });
});


In the above code, if there is no error in the ajax request, the resources (HTML document and other data attached; required, to it) will be downloaded to your page and then they will be added to the pop-up window which at that time is empty. Once that is done, it will be shown using that method .show().

For more information on jQuery ajax, please read this document[^].
 
Share this answer
 
Comments
knackCoder 24-Dec-14 15:38pm    
Afzaal ,Thanks for help ,but i want to load an ASP.NET .aspx page(It will contain server side code) instead of an HTML page.
Philippe Mori 24-Dec-14 16:07pm    
You can load any page... The server will process the page and send back HTML code as usual.
knackCoder 25-Dec-14 0:47am    
Philippe could you provide me code for the solution you are talking about. Actually i want to load an .aspx page in a pop up window.Thanks in advance.
Afzaal Ahmad Zeeshan 25-Dec-14 1:58am    
Did you even try to follow what I just said? If you did you would have got what you wanted. Pillippe is also saying the same.

In the response, server-side code is never sent back, just the HTML markup is sent to the client. That is default behaviour.
You can use javascript to open popup window.it can be a HTML or ASPX page.
In button client click event call the javascript to open the popup window.
here is the Sample code.

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

    function openPopup() {

            window.open("YOURpopuppage.aspx", "_blank", "WIDTH=1080,HEIGHT=790,scrollbars=no, menubar=no,resizable=yes,directories=no,location=no");  
               
                }
//<![CDATA[    
//
</script>

   <asp:imagebutton id="btnpopup" runat="server" onclientclick="return openPopup()" xmlns:asp="#unknown" />


If you want to call the Javascript function during your Server Side button click event

C#
  protected void Page_Init(object source, System.EventArgs e)
    {
  btnpopup.Attributes.Add("onclick", "return openPopup();");
}
 
Share this answer
 
v4

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