i am running into a problem that i have a jquery modal popup in my usercontrol that i show on a click of a button and user selects something from datalist and then i returned some value on the parent user control in a hidden field all is fine till here but after the click on the select button i want the jquery modal to be closed also here is some code of the div which i show in modal diaog
我遇到一个问题,我在我的usercontrol中有一个jquery模式弹出窗口,我点击一个按钮显示,用户从datalist中选择一些东西,然后我在隐藏字段中的父用户控件上返回一些值,一切都很好,直到在这里,但点击选择按钮后我想要关闭jquery模式也在这里是我在模态diaog中显示的div的一些代码
<asp:UpdatePanel ID="upDatagrabber" runat="server">
<ContentTemplate>
<table>
<tr>
<td>Select Category</td><td><asp:DropDownList ID="ddlTemplateCatagory"
runat="server" AutoPostBack="True"></asp:DropDownList></td>
</tr>
<tr>
<td colspan="2">
<table cellspacing="0" cellpadding="0" border="0" style="float:left;padding:5px;margin:5px;width:200px;display:block;">
<tbody>
<tr>
<asp:DataList ID="dlTemplates" runat="server" RepeatColumns="3"
RepeatDirection="Horizontal" onitemcommand="dlTemplates_ItemCommand">
<ItemTemplate>
<td style="border-right: gainsboro 1px solid; border-top: gainsboro 1px solid;
border-left: gainsboro 1px solid; border-bottom: gainsboro 1px solid;padding:5px;">
<table><tr><td>
<%# Eval("NewsletterName").ToString()%>
</td></tr>
<tr><td><asp:Button ID="btnSelectNL_Template" Text="Select" runat="server" CssClass="button" CommandArgument='<%# Eval("NewsletterId").ToString()%>' CommandName="Select"/></td></tr>
</table>
</td>
</ItemTemplate>
</asp:DataList>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</ContentTemplate>
and in the ItemCommandEvent I tried following
在ItemCommandEvent中我试过以下
protected void dlTemplates_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "Select")
{
int SelectedNewsletterId = int.Parse(e.CommandArgument.ToString());
if (NewsletterSelectedHandler!= null)
{
e.Item.Attributes.Add("onclick","jQuery('#mydialog').dialog('close');");
NewsletterSelectedHandler(SelectedNewsletterId);
}
}
}
EDIT
编辑
i shown the popup using this in my code behind
我在后面的代码中使用了这个弹出窗口
ScriptManager.RegisterClientScriptBlock(this.Page, Page.GetType(), "change", "jQuery('#mydialog').dialog('open');closedialog = 1;jQuery('#mydialog').parent().appendTo(jQuery('form:aspnetForm'));", true);
popup shown successfully but i could not close it on the button click of datalist child button i tried code provided by tugburk i checked the error console also there is no error code for close is as followd :
popup显示成功,但我无法关闭它按下按钮点击datalist子按钮我试过tugburk提供的代码我检查错误控制台也没有错误代码关闭是如下:
<script type="text/javascript">
$(document).ready(function(){
$('#ctl00_ContentPlaceHolder1_NewsletterWizard1_TemplatePicker1_dlTemplates_ctl00_btnSelectNL_Template').click(function(){
$('#mydialog').dialog('close');
});
});
</script>
Any help would be appreciable Many thanks in the Advance
任何帮助都会很明显非常感谢Advance
1 个解决方案
#1
2
use the following code;
使用以下代码;
$(document).ready(function(){
$('#<%= btnSelectNL_Template.ClientID %>').click(function(){
$('#id_of_your_dialog_element').dialog('close');
});
});
EDIT : you are hardcoding your button id there;
编辑:你在那里硬编码你的按钮ID;
ctl00_ContentPlaceHolder1_NewsletterWizard1_TemplatePicker1_dlTemplates_ctl00_btnSelectNL_Template
ctl00_ContentPlaceHolder1_NewsletterWizard1_TemplatePicker1_dlTemplates_ctl00_b tnSelectNL_Template
DataList will produce multiple buttons if you have multiple records. add a class name to that button, and try to write a code against it
如果您有多个记录,DataList将生成多个按钮。为该按钮添加一个类名,并尝试编写代码
$('.MyButtonClass').click(function(){
$('#mydialog').dialog('close');
});
#1
2
use the following code;
使用以下代码;
$(document).ready(function(){
$('#<%= btnSelectNL_Template.ClientID %>').click(function(){
$('#id_of_your_dialog_element').dialog('close');
});
});
EDIT : you are hardcoding your button id there;
编辑:你在那里硬编码你的按钮ID;
ctl00_ContentPlaceHolder1_NewsletterWizard1_TemplatePicker1_dlTemplates_ctl00_btnSelectNL_Template
ctl00_ContentPlaceHolder1_NewsletterWizard1_TemplatePicker1_dlTemplates_ctl00_b tnSelectNL_Template
DataList will produce multiple buttons if you have multiple records. add a class name to that button, and try to write a code against it
如果您有多个记录,DataList将生成多个按钮。为该按钮添加一个类名,并尝试编写代码
$('.MyButtonClass').click(function(){
$('#mydialog').dialog('close');
});