如何使用asp.net中的链接按钮调用JQuery对话框
我的网站中有一个 Jquery 对话框。该对话框用于获取用户评论。目前,我使用以下代码来执行Javascript函数并且工作正常:
**<a href="#dialog" name="modal">Rate this</a>**
<div id="dialog" class="window"></div>
<div id="mask"></div>
它调用的Javascript代码如下:
$(document).ready(function() {
//select all the a tag with name equal to modal
$('a[name=modal]').click(function(e) {
//Cancel the link behavior
e.preventDefault();
//Get the A tag
var id = $(this).attr('href');
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set heigth and width to mask to fill up the whole screen
$('#mask').css({ 'width': maskWidth, 'height': maskHeight });
//transition effect
$('#mask').fadeIn(1000);
$('#mask').fadeTo("slow", 0.8);
//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
//Set the popup window to center
$(id).css('top', winH / 2 - $(id).height() / 2);
$(id).css('left', winW / 2 - $(id).width() / 2);
//transition effect
$(id).fadeIn(2000);
});
});
//if close button is clicked
$("input[id$='btnClose']").click(function(e) {
e.preventDefault();
$('#mask').hide();
$('.window').hide();
});
由于href没有服务器端单击事件,我需要使用链接按钮调用javascript。我尝试了多种方法但未能得到实际结果。
最后,我需要更改此调用**对此进行评分**
到链接按钮,以便我可以捕获单击事件。
I have a Jquery dialog box in my website. This dialog box is meant for getting user comments. At present, I'm using the following code to execute the Javascript function and is working fine:
**<a href="#dialog" name="modal">Rate this</a>**
<div id="dialog" class="window"></div>
<div id="mask"></div>
The Javascript code which it calls as follows:
$(document).ready(function() {
//select all the a tag with name equal to modal
$('a[name=modal]').click(function(e) {
//Cancel the link behavior
e.preventDefault();
//Get the A tag
var id = $(this).attr('href');
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set heigth and width to mask to fill up the whole screen
$('#mask').css({ 'width': maskWidth, 'height': maskHeight });
//transition effect
$('#mask').fadeIn(1000);
$('#mask').fadeTo("slow", 0.8);
//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
//Set the popup window to center
$(id).css('top', winH / 2 - $(id).height() / 2);
$(id).css('left', winW / 2 - $(id).width() / 2);
//transition effect
$(id).fadeIn(2000);
});
});
//if close button is clicked
$("input[id$='btnClose']").click(function(e) {
e.preventDefault();
$('#mask').hide();
$('.window').hide();
});
Since href does not have server side click event, I need to call the javascript using the link button. I tried several ways but failed to get the actual result.
To Conclude I need to change this call **<a href="#dialog" name="modal">Rate this</a>**
to a Link button so that I can trap the click event.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 RegisterStartupScript 来完成此操作,它允许您在服务器端调用结束时运行 Javascript。可以在此处找到示例> http://www.dotnetcurry.com/ShowArticle.aspx?ID=200
说我强烈建议您甚至在用户单击之前尝试操作链接,即在页面加载时,而不是将锚标记转换为链接按钮。
当页面加载时,您应该检查请求客户端是否是注册用户。如果他显示相同的
**Rate this**
并在In case you看到该用户尚未注册,那么您可以隐藏链接或将模态div更改为显示,您还没有注册,请点击此处进行注册。
希望它有意义。
You can do this using the RegisterStartupScript which allows you to run Javascript at the end of a server side call. An example can be found here > http://www.dotnetcurry.com/ShowArticle.aspx?ID=200
Saying that I would strongly recommend that you should try manipulating the link even before the user clicks i.e. when the Page is loading instead of converting the anchor tag into a Linkbutton.
When the page is loading, you should check at that time whether the requesting client is a registered user or not. If he is then show the same
**<a href="#dialog" name="modal">Rate this</a>**
and add the rating form inside theIn case you see that the user is not registered, then you can either the hide the link or change the modal div to show, you are not registered, please click here for registration.
Hope it make sense.