我想从带有母版页的asp.net页面打开一个jQuery UI对话框。在母版页的页面中,代码工作正常,但母版页无效。
代码是:
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/privado/master/interior.master" CodeBehind="WebForm3.aspx.vb" Inherits="ProyectoDemo.WebForm3" %>
<asp:Content ID="Content1" ContentPlaceHolderID="headInterior" runat="server">
<link type="text/css" href="Styles/jquery-ui-1.8.16.custom.css" rel="stylesheet" />
<link href="Styles/addhunters.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui- 1.8.16.custom.min.js"></script>
<style type="text/css">
/*demo page css*/
body{ font: 62.5% "Trebuchet MS", sans-serif; margin: 50px;}
.demoHeaders { margin-top: 2em; }
#dialog_link {padding: .4em 1em .4em 20px;text-decoration: none;position: relative;}
#dialog_link span.ui-icon {margin: 0 5px 0 0;position: absolute;left: .2em;top: 50%;margin-top: -8px;}
ul#icons {margin: 0; padding: 0;}
ul#icons li {margin: 2px; position: relative; padding: 4px 0; cursor: pointer; float: left; list-style: none;}
ul#icons span.ui-icon {float: left; margin: 0 4px;}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="contenidoInterior" runat="server">
<script type="text/javascript">
$(function () {
// Dialog
$('#dialog').dialog({
autoOpen: false,
width: 600,
height: 400,
buttons: {
"Ok": function () {
$(this).dialog("close");
},
"Cancelar": function () {
$(this).dialog("close");
}
}
});
// Dialog Link
$('#Boton').click(function () {
$('#dialog').dialog('open');
return false;
});
});
</script>
<div id="uno">
<h2 class="demoHeaders">Dialog</h2>
<asp:TextBox ID="TextBox1" runat="server" Text="prueba" ></asp:TextBox>
<p><a href="#" id="dialog_link" class="ui-state-default ui-corner-all"><span class="ui-icon ui-icon-newwin"></span>Open Dialog</a></p>
<asp:LinkButton ID="Boton" runat="server">LinkButton</asp:LinkButton>
<asp:Button ID="Button1" runat="server" Text="Button" />
<!-- ui-dialog -->
<div id="dialog" title="Dialog Title">
<p>Dialog text</p>
</div>
</div>
我认为问题是如何引用&#34;对话框&#34;在占位符内。我尝试了几种方法,但我找不到解决方案。
有人知道如何解决这个问题吗?
提前谢谢!
哈维尔
答案 0 :(得分:1)
您需要考虑几件事情:
window["common"] = {
liveDialog: function(btnId) {
$(btnId).live(click,common.showDialog);
return false;
},
showDialog() : function(){
$('#dialog').dialog({
autoOpen: false,
width: 600,
height: 400,
buttons: {
"Ok": function () {
$(this).dialog("close");
},
"Cancelar": function () {
$(this).dialog("close");
}
}
});
}
}
public void RegisterDialog(clientBtnId)
{
this.page.ClientScript.RegisterStartupScript(this.Page.GetType(),"__registerDialg","common.liveDialog('"+clientBtnId+"');",true);
}
- 已编辑的示例 -
例如,您的母版页类名是CustomSiteMaster,您可以编写((CustomSiteMaster)this.Master).RegisterDialog(button1.ClientID);
- 编辑结束 -
它可以正常工作
答案 1 :(得分:0)
添加到LinkButton OnClientClick属性,如下所示:
<asp:LinkButton ID="Boton" runat="server"
OnClientClick="$('#dialog').dialog('open'); return false;" >LinkButton</asp:LinkButton>
此外,如果您想通过id选择服务器端控件,请使用以下选择器语法:
$("#<%= ControlID.ClientID %>")
答案 2 :(得分:0)
要在内容占位符中找到任何控件,请确保使用如下语法:
$('#ContentPlaceHolderId_ControlId')
答案 3 :(得分:0)
未加载jQuery UI,因为您的src
属性中有一个额外的空格:
<script type="text/javascript" src="js/jquery-ui- 1.8.16.custom.min.js"></script>
只需更改为:
<script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
jQuery UI可能会正常加载,您将停止接收"the object does not support this property or method"
条消息。
答案 4 :(得分:0)
我有解决“谜”的问题。问题很简单。对jQuery-UI的.js文件的引用是在Conten1占位符中,我把这两行放在Conten2占位符中,这个内容有一个javascript函数才能打开对话框。
完整且有效的代码如下:
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/privado/master/interior.master" CodeBehind="WebForm3.aspx.vb" Inherits="ProyectoDemo.WebForm3" %>
<asp:Content ID="Content1" ContentPlaceHolderID="headInterior" runat="server">
<link type="text/css" href="Styles/jquery-ui-1.8.16.custom.css" rel="stylesheet" />
<link href="Styles/addhunters.css" rel="stylesheet" type="text/css" />
<%--<%@ MasterType VirtualPath="~/privado/master/Interior.master"%>--%>
<style type="text/css">
/*demo page css*/
body{ font: 62.5% "Trebuchet MS", sans-serif; margin: 50px;}
.demoHeaders { margin-top: 2em; }
#dialog_link {padding: .4em 1em .4em 20px;text-decoration: none;position: relative;}
#dialog_link span.ui-icon {margin: 0 5px 0 0;position: absolute;left: .2em;top: 50%;margin-top: -8px;}
ul#icons {margin: 0; padding: 0;}
ul#icons li {margin: 2px; position: relative; padding: 4px 0; cursor: pointer; float: left; list-style: none;}
ul#icons span.ui-icon {float: left; margin: 0 4px;}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="contenidoInterior" runat="server">
<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui- 1.8.16.custom.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
alert('hola');
$('#dialog').dialog({
autoOpen: false,
width: 600,
height: 400,
buttons: {
"Ok": function () {
$(this).dialog("close");
},
"Cancelar": function () {
$(this).dialog("close");
}
}
});
$('#MainContent_contenidoInterior_Boton').click(function () {
$('#dialog').dialog('open');
return false;
});
});
</script>
<div id="uno" >
<h2 class="demoHeaders">Dialog</h2>
<asp:TextBox ID="TextBox1" runat="server" Text="prueba" ></asp:TextBox>
<p><a href="#" id="dialog_link" class="ui-state-default ui-corner-all"><span class="ui-icon ui-icon-newwin"></span>Open Dialog</a></p>
<asp:LinkButton ID="Boton" runat="server">LinkButton</asp:LinkButton>
<asp:Button ID="Button1" runat="server" Text="Button" />
<!-- ui-dialog -->
<div id="dialog" title="Dialog Title">
<p>Dialog text</p>
</div>
</div>
感谢您的回答。
哈维尔