Skip to main content

हाउ To Open NewWindow From CodeBehind Using ASP.NET

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.IO;
using System.Collections;
using System.Web.UI;
namespace com.StadiumRoar.Utility
{

   public class Utilities
   {
       public static void OpenPopUp(System.Web.UI.WebControls.WebControl opener,
   string PagePath, string windowName, int width, int height)
       {
           string clientScript;
           string windowAttribs;
           //Building Client side window attributes with width and height.//
           //Also the the window will be positioned to the middle of the screen//
           windowAttribs = "width=" + width + "px,"
  + "height=" + height + "px,"
  + "left=\'+((screen.width -"
  + width + ") / 2)+\',"
  + "top=\'+ (screen.height - "
  + height + ")/ 2+\'";

          //***Building the client script- window.open, with additional parameters***///
           clientScript = "window.open(\'" + PagePath + "\',\'"
 + windowName + "\',\'"
 + windowAttribs + "\');return false;";
           //regiter the script to the clientside click event of the 'opener' control*****///
           opener.Attributes.Add("onClick", clientScript);
       }
   }
}
How To Use This Method 1. Add Button controls in aspx page. <asp:Button ID="btn" runat="server" Text="Open Pop Up" /> 2.Add Below code in Page_load of the aspx page. Utilities.OpenPopUp(btn, "PoppEmail.aspx", "EmailPro", 700, 500);

Comments

Popular posts from this blog