Click here to Skip to main content
11,931,584 members (67,625 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET
I have a client side script as below
<asp:Button ID="btnplay" runat="server" Text="Play Selected" ForeColor="red" Font-Bold="true" CommandName="PLAY" onClick="populate" OnClientClick="'Default6.aspx','List','scrollbars=no,resizable=no,width=420,height=330'); return false;"/>
I want to execute the server side script before onclientclick to show popup window
because I want get some data from the table to show it in the popup window.
I know I can put Response.write(..) in the server side to show the popup window, but in that case if popup blocker sets for the site it blocks it from showing the window.

I just want to show the popup window filled with the data without popup blocking when the user clicks the command button. The above code doesn't execute serverside script before onclientclick so it is erroring. Is there any way to do it?
Posted 13-Jan-13 20:28pm
Reji Ab566
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

onClick is work on server side. OnClientClick will work on client side, after rendering the page, OnClientClick is a equivalent method for client side onclick event. As you know normally, client side events occur before the server side events. So that the "OnClientClick" event occurs before the OnClick event.

Regarding your requirement, you have to change your code. Basically you have to remove the "OnClientClick" attribute. And then after the postback (when the OnClick" event occurs you have to register the following script.'Default6.aspx','List','scrollbars=no,resizable=no,width=420,height=330');

Please check the following link for more detail[^]

basically you should look RegisterClientScriptBlock and RegisterStartupScript

Please try, if you are still having issue, please let me know I'll provide the sample.

if you want to open this without you have to use the DIV popup. following link will help you[^][^][^]

See this also[^]
Reji Ab 14-Jan-13 5:53am
Thanks Tharaka for your reply. I looked into the link and I can see RegisterClientScriptBlock and RegisterStartupScript both used in server side if I open the popup from the server side popup blocker blocks it. I don't want to do that. If I use ..... in onclick it shows an error.
Can u please provide me the sample code to pop up window without blocking.
Tharaka MTR 14-Jan-13 7:35am
if you use to open a popup window, it will blocked by popup blocker by default. If you want to open a popup without blocking, you have to use div popup. Please check improved solution
Reji Ab 14-Jan-13 9:21am
Thanks Tharaka. I want to show an asp page as popup. Div popup shows only a popup window
Tharaka MTR 14-Jan-13 11:16am
if you want you can display the .aspx page inside the DIV. no problem for that. but If you want to open it as, then you should display some information or FAQ to client, to disable the popup blocker for your site. Otherwise, it will be blocked, if the user enable the popup blocker.
Reji Ab 14-Jan-13 11:53am works well without popup blocking if I use it in client side. The problem here is I just want to show it after executes the server side script
Tharaka MTR 14-Jan-13 23:13pm
I can fully agreed to " works well without popup blocking if I use it in client side." this part.

But. you can try this way. First you create a JavaScript function like,

function openpopup(){'Default6.aspx','List','scrollbars=no,resizable=no,width=420,height=330');
And then you can call that function using the "RegisterClientScriptBlock" method.

But I'm not fully sure this will solve the popup blocking issue. plz try and let me know the results.
Reji Ab 15-Jan-13 2:16am
It works but popup blocking issue still there
Tharaka MTR 15-Jan-13 5:56am
Yes, that's what I said. you can't eliminate the popup blocking issue. it is a user privilege to enable or disable the popup blocker. either you display a message to them to enable popup blocker for your site, or you have to use DIV popup.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

do like this
function populate()
//write the coding of onclick event 
///now write the coding for onclientclick event'Default6.aspx','List','scrollbars=no,resizable=no,width=420,height=330'); return false;

Zafar Sultan 14-Jan-13 8:08am
I don't want to sound offensive but you should buy a good book on ASP.Net. The OP is asking about OnClick (server side event) and OnClientClick (executed on client side) and you are providing an example for sequence of commands in JavaScript.
Reji Ab 18-Jan-13 5:43am
<script> function populate() { document.submit.form(); ///now write the coding for onclientclick event'Default6.aspx','List','scrollbars=no,resizable=no,width=420,height=330'); return false; } </script>

After submitting the form it never executes the second part of the function

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.151126.1 | Last Updated 14 Jan 2013
Copyright © CodeProject, 1999-2015
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