Jax
Jax

Reputation: 997

How to popup a page on button click?

I want to pop up a new page in the main page of my application . The location must be in center,can't be sizable, it shouldn't be opened as a new tab in the main page , the bar with the options for : closing,minimize/miximize shouldn't be there.

Here is my code:

  protected void Page_Load(object sender, EventArgs e)
        {
           HyperLink1.Attributes.Add("onclick", "window.open('WebForm1.aspx',null,'height=350, width=250,status= no, resizable= no, scrollbars=no, toolbar=no,location=center,menubar=no')");
        }

But....

Can someone help me?

Thanks

Upvotes: 0

Views: 3387

Answers (1)

Kapil Khandelwal
Kapil Khandelwal

Reputation: 16144

Try this:

protected void Page_Load(object sender, EventArgs e)
        {
           HyperLink1.Attributes.Add("onclick", "centeredPopup('WebForm1.aspx','myWindow','500','300','yes');return false");
        }


<script language="javascript">
var popupWindow = null;
function centeredPopup(url,winName,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
popupWindow = window.open(url,winName,settings)
}
</script>

For more details - see this

Upvotes: 1

Related Questions