如何在onclientclick之前执行onclick [英] how to execute onclick before onclientclick
问题描述
我有一个客户端脚本如下
< asp:按钮 ID = btnplay runat = server 文字 = 播放所选 ForeColor = red 字体粗体 = true CommandName = 播放 onClick = 填充 OnClientClick = javascript:window.open('Default6.aspx','List','scrollbars = no,resizable = no,width = 420,height = 330');返回false; / >
我想在onclientclick之前执行服务器端脚本以显示弹出窗口
因为我想从表中获取一些数据以在弹出窗口中显示它。
我知道我可以在服务器端放置Response.write(..)来显示弹出窗口,但是在这种情况下,如果弹出窗口阻止程序为站点设置它阻止它显示窗口。
我只是想在用户单击命令按钮时显示填充了数据的弹出窗口而没有弹出窗口阻止。上面的代码在onclientclick之前没有执行serverside脚本,所以它是错误的。有没有任何方法吗?
onClick
在服务器端工作。OnClientClick
将在客户端工作,在呈现页面后,OnClientClick
是客户端onclick的等效方法
ev正如您所知,客户端事件发生在服务器端事件之前。因此OnClientClick
事件发生在OnClick
事件之前。
关于您的要求,您必须更改您的代码。基本上你必须删除OnClientClick
属性。然后在回发之后(当OnClick
事件发生时,你必须注册以下脚本。
< pre lang =Javascript> javascript: window .open(' Default6.aspx',' List',' scrollbars = no,resizable = no,width = 420,height = 330');
请查看以下链接了解更多详情
http://msdn.microsoft.com/en-us/library/ms178207(v = vs.80).aspx [ ^ ]
基本上你应该看RegisterClientScriptBlock
和RegisterStartupScript
请试试,如果你还有问题,请告诉我,我会提供样品。
如果你想在没有窗户的情况下打开它。打开你必须使用DIV弹出窗口。以下链接将帮助您
http://lokeshdhakar.com/projects/lightbox2/ [< a href =http://lokeshdhakar.com/projects/lightbox2/target =_ blanktitle =New Window> ^ ]
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ModalPopup/ModalPopup.aspx [ ^ ]
http://proudmonkeycontrols.codeplex.com/documentation [ ^ ]
看到这个也是
http://forums.asp.net/p/1382753/2938303.aspx# 29383 03 [ ^ ]
这样做
< script>
function populate()
{
// 编写onclick事件的编码
// /现在编写onclientclick事件的编码
window .open(' Default6.aspx',' List' ,' scrollbars = no,resizable = no,width = 420,height = 330'); 返回 false ;
}
< / script>
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?
onClick
is work on server side.OnClientClick
will work on client side, after rendering the page,OnClientClick
is a equivalent method for client sideonclick
event. As you know normally, client side events occur before the server side events. So that the "OnClientClick
" event occurs before theOnClick
event.
Regarding your requirement, you have to change your code. Basically you have to remove the "OnClientClick
" attribute. And then after the postback (when theOnClick
" 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 lookRegisterClientScriptBlock
andRegisterStartupScript
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[^]
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>
这篇关于如何在onclientclick之前执行onclick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!