从codebehind打开对话框的jQuery [英] open jQuery Dialog from codebehind
问题描述
所以,我必须展示从codebehind一个jQuery UI的对话框。结果
我用尽了一切:<一href=\"http://blog.dreamlabsolutions.com/post/2009/06/03/run-jQuery-$c$c-from-ASPNET-Server-Side.aspx\"相对=nofollow>这个,这 ,<一个href=\"http://stackoverflow.com/questions/3039714/how-register-call-jquery-function-from-asp-net-usercontrol-from-$c$cbehind-file\">this,并且也改变了这些问题的答案,以测试它是否适用于我,但不工作。结果
我使用的第一个解决方案,因为它的组织。它的工作原理,如果我使用alert('不管'),而不是我的jQuery对话框code。所以我知道它的工作,但没有与对话发生。我和颜色框试了一下还了,也不工作。
谁能给我一个解决方法吗?这将是一个preciated。结果
谢谢。
我的aspx:
HEAD
&LT;脚本类型=文/ JavaScript的&GT; 功能BindEvents(){
$ .fx.speeds._default = 1000;
$(文件)。就绪(函数(){
变种DLG = $(#DivMostrarIguales)。对话框({
的AutoOpen:假的,
显示:褶皱,
隐藏:夹子,
宽度:500,
身高:500
});
。dlg.parent()appendTo(jQuery的(形式:一是));
});
}&LT; / SCRIPT&GT;
ENDHEAD
&LT; ASP:内容ID =内容2ContentPlaceHolderID =日程地址搜索Maincontent=服务器&GT;
&LT; ASP:的UpdatePanel =服务器ID =upTotal&GT;
&LT;&的ContentTemplate GT;
&LT;脚本类型=文/ JavaScript的&GT;
Sys.Application.add_load(BindEvents);
&LT; / SCRIPT&GT; ....
&所述; TR&GT;
&LT; TD类=左翼&GT;
(*)NÚMEROUNICO:
&LT; / TD&GT;
&LT; TD类=Derecha&GT;
&LT; ASP:文本框ID =tbNumeroUnico=服务器&GT;&LT; / ASP:文本框&GT;
&LT; ASP:按钮的ID =btMostrarIgualesEntrante=服务器文本=Revisar司亚existe
的OnClick =MostrarVentanaIgualesEntrante的ValidationGroup =无的CausesValidation =假
的CssClass =按钮/&GT;
&LT; ASP:标签=服务器ID =lbNumeroUnicoEntrante文本=德贝digitar EL formato correcto德尔NÚMEROUNICO(COMPLETO)
可见=假的CssClass =ErrorCampo&GT;&LT; / ASP:标签&gt;
&LT; / TD&GT;
&LT; / TR&GT; ...
&LT; DIV ID =DivMostrarIguales称号=NÚMEROUNICO Igual&GT;
随你
&LT; / DIV&GT;
&LT; /&的ContentTemplate GT;
&LT; / ASP:的UpdatePanel&GT;
&LT; / ASP:内容&GT;
我.CS功能:
私人字符串getjQuery code(字符串JS codetoRun)
{
StringBuilder的SB =新的StringBuilder();
sb.AppendLine($(文件)。就绪(函数(){);
sb.AppendLine(JS codetoRun);
sb.AppendLine(});); 返回sb.ToString();
} 私人无效runjQuery code(字符串JS codetoRun)
{ ScriptManager的requestSM = ScriptManager.GetCurrent(本);
如果(requestSM = NULL&放大器;!&安培; requestSM.IsInAsyncPostBack)
{
ScriptManager.RegisterClientScriptBlock(这一点,
typeof运算(页)
Guid.NewGuid()。toString()方法,
getjQuery code(JS codetoRun)
真正);
}
其他
{
ClientScript.RegisterClientScriptBlock(typeof运算(页)
Guid.NewGuid()。toString()方法,
getjQuery code(JS codetoRun)
真正);
}
} 保护无效MostrarVentanaIgualesEntrante(对象发件人,EventArgs的发送)
{
CargarGridMostrarIgualesEntrante();
runjQuery code(。$('#DivMostrarIguales')对话框(打开));
}
首先做出对话框打电话来创建它。
.dialog({的AutoOpen:假})// {} =设置
,然后打开它。
.dialog(公开)
So i have to show a jquery UI Dialog from codebehind.
I've tried everything: this, this, this, and also changed those answers to test if it works with me but is not working.
I'm using the first solution because it's organized. It works if i use alert('whatever') instead of my jquery dialog code. so i know its working, but nothing happens with the dialog. I've tried it with colorbox also, and not working either.
Can anyone give me a workaround please? It would be apreciated.
Thank you.
My aspx:
HEAD
<script type="text/javascript">
function BindEvents() {
$.fx.speeds._default = 1000;
$(document).ready(function () {
var dlg = $("#DivMostrarIguales").dialog({
autoOpen: false,
show: "fold",
hide: "clip",
width: 500,
height: 500
});
dlg.parent().appendTo(jQuery("form:first"));
});
}
</script>
ENDHEAD
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:UpdatePanel runat="server" ID="upTotal">
<ContentTemplate>
<script type="text/javascript">
Sys.Application.add_load(BindEvents);
</script>....
<tr>
<td class="Izquierda">
(*) Número único:
</td>
<td class="Derecha">
<asp:TextBox ID="tbNumeroUnico" runat="server"></asp:TextBox>
<asp:Button ID="btMostrarIgualesEntrante" runat="server" Text="Revisar si ya existe"
OnClick="MostrarVentanaIgualesEntrante" ValidationGroup="none" CausesValidation="false"
CssClass="Button" />
<asp:Label runat="server" ID="lbNumeroUnicoEntrante" Text="Debe digitar el formato correcto del número único (completo)"
Visible="false" CssClass="ErrorCampo"></asp:Label>
</td>
</tr>...
<div id="DivMostrarIguales" title="Número Único Igual">
WhatEver
</div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
My .CS functions:
private string getjQueryCode(string jsCodetoRun)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("$(document).ready(function() {");
sb.AppendLine(jsCodetoRun);
sb.AppendLine(" });");
return sb.ToString();
}
private void runjQueryCode(string jsCodetoRun)
{
ScriptManager requestSM = ScriptManager.GetCurrent(this);
if (requestSM != null && requestSM.IsInAsyncPostBack)
{
ScriptManager.RegisterClientScriptBlock(this,
typeof(Page),
Guid.NewGuid().ToString(),
getjQueryCode(jsCodetoRun),
true);
}
else
{
ClientScript.RegisterClientScriptBlock(typeof(Page),
Guid.NewGuid().ToString(),
getjQueryCode(jsCodetoRun),
true);
}
}
protected void MostrarVentanaIgualesEntrante(object sender, EventArgs e)
{
CargarGridMostrarIgualesEntrante();
runjQueryCode("$('#DivMostrarIguales').dialog('open')");
}
First make a call to dialog to create it.
.dialog({ autoOpen: false }) //{} = settings
and then open it..
.dialog('open')
这篇关于从codebehind打开对话框的jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!