【问题标题】:jquery dialog form with asp:hyperlink带有 asp:hyperlink 的 jquery 对话框表单
【发布时间】:2012-12-27 10:00:10
【问题描述】:

我在用 asp.net 表单实现 JQuery 对话框时遇到问题。当我点击#hlChangePassword 时,什么也没有发生。这是我下面的代码:

<script type="text/javascript">

    jQuery(document).ready(function () {
        jQuery('#hlChangePassword').click(function () {
            var dlg = jQuery('div#ChangePass').dialog({
                width: 500,
                height: 500,
                modal: true,
                buttons: {},
                open: function (event, ui) {
                    $(".ui-dialog-titlebar-close").hide();
                }
            });
            dlg.parent().appendTo(jQuery("form:first"));
        });
    });

</script>

html

<asp:HyperLink ID="hlChangePassword" 
runat="server" NavigateUrl="#">Change Password</asp:HyperLink>

<div id="ChangePass" style="display:none;">
//The content
</div>

我不知道是什么问题。请帮帮我。

【问题讨论】:

    标签: asp.net jquery-ui dialog


    【解决方案1】:

    用户事件.preventDefault();防止回帖如下

     jQuery(document).ready(function () {
        jQuery('#hlChangePassword').click(function (event) {
            var dlg = jQuery('div#ChangePass').dialog({
                width: 500,
                height: 500,
                modal: true,
                buttons: {},
                open: function (event, ui) {
                    $(".ui-dialog-titlebar-close").hide();
                }
            });
            dlg.parent().appendTo(jQuery("form:first"));
            event.preventDefault();
    
        });
    });
    

    因为hlChangePassword 是一个服务器控件,所以它会回发。要克服这个问题,您应该使用event.preventDefault
    此外,您正在使用 id 选择器,由于母版页或用户控制,它可以在运行时更改。因此,如果您使用的是 asp.net 4.0 或更高版本,请使用服务器 id 或静态 id 作为链接,如下所示

    ClientIDMode="Static"
    
    
    <asp:HyperLink ID="hlChangePassword"  ClientIDMode="Static"
     runat="server" NavigateUrl="#">Change Password</asp:HyperLink>
    

    【讨论】:

    • 你的超链接在浏览器中的id是什么??一样吗
    • 我猜是与母版页有关的问题。使用母版页中的内容表单。你能解释一下吗?
    • 浏览器中的id一模一样!
    • 你使用的asp.net版本是什么
    【解决方案2】:

    宾果游戏...
    脚本 src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"> 添加上面的行,如果没有 ui.js,它将无法工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多