fkr fkr - 1 year ago 74
C# Question

Javascript code to open pop-up window on button click?

I want to know how to write a javascript code that will open a new 600*300 pop-up window on button click.

Let's say i have a open-up button in my Books.aspx ...and when i click "display", i want a few books to be display in the pop-up window, which is another web-form called BooksAuthor.aspx

This is what i've tried so far:

Option 1

<asp:TextBox ID="text1" runat="server"></asp:TextBox>
<asp:Button ID="button1" runat="server" onClick="'BooksAuthor.aspx');" Text="Display" /><br /><br />

Option 2

<asp:TextBox ID="text1" runat="server"></asp:TextBox>
<asp:Button ID="button1" runat="server" onClick="openWindow();"Text="Display" /><br /><br />

<script type="text/javascript">
function openWindow()
{"BooksAuthor.aspx", "status=1,width=600,height=300");

Nothing seems to be working. Any ideas?

Thank you!

Answer Source

you have to call javascript on onClientClick

<asp:Button ID="button1" runat="server" OnClientClick="'BooksAuthor.aspx');" Text="Display" /><br /><br />


<asp:Button ID="button1" runat="server" OnClientClick="openWindow();" Text="Display" /><br /><br />

<script type="text/javascript">
function openWindow() {"BooksAuthor.aspx", "status=1,width=600,height=300");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download