Click here to Skip to main content
Rate this: bad
good
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=" 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 13-Jan-13 19:28pm
Reji Ab564
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

do like this
<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>
  Permalink  
Comments
Zafar Sultan at 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 at 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.....
Rate this: bad
good
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.
 
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[^]
  Permalink  
v3
Comments
Reji Ab at 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 at 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 at 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 at 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 at 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
Tharaka MTR at 14-Jan-13 23:13pm
   
I can fully agreed to "window.open 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,
 
<script>
function openpopup(){
window.open('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 at 15-Jan-13 2:16am
   
It works but popup blocking issue still there
Tharaka MTR at 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.

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



Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 14 Jan 2013
Copyright © CodeProject, 1999-2014
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