Click here to Skip to main content
15,882,552 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a client side script as below
XML
<asp:Button ID="btnplay" runat="server" Text="Play Selected" ForeColor="red" Font-Bold="true" CommandName="PLAY" onClick="populate" OnClientClick=" javascript:window.open('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
v2

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.

JavaScript
javascript:window.open('Default6.aspx','List','scrollbars=no,resizable=no,width=420,height=330');


Please check the following link for more detail
http://msdn.microsoft.com/en-us/library/ms178207(v=vs.80).aspx[^]

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 window.open you have to use the DIV popup. following link will help you
http://lokeshdhakar.com/projects/lightbox2/[^]

http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ModalPopup/ModalPopup.aspx[^]

http://proudmonkeycontrols.codeplex.com/documentation[^]

See this also
http://forums.asp.net/p/1382753/2938303.aspx#2938303[^]
 
Share this answer
 
v3
Comments
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 javascript:window.open ..... 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 window.open 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 window.open, 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    
window.open 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
do like this
JavaScript
<script>
function populate()
{
//write the coding of onclick event 

///now write the coding for onclientclick event
window.open('Default6.aspx','List','scrollbars=no,resizable=no,width=420,height=330'); return false;

}
</script>
 
Share this answer
 
Comments
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 window.open('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 window.open.....

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