[英]How I can use the Controls from jquery PopUpDialog in my ASP.NEt Application
My Application: 我的应用程序:
I have a ASP.NET Application with two parts. 我有一个包含两个部分的ASP.NET应用程序。 First part is the "Absence" Part and the second part is "Signature".
第一部分是“缺席”部分,第二部分是“签名”。 This Application create this parts Automatic.
此应用程序自动创建此零件。 For Absence the User must input the Enddate from this absence and a representative.
对于缺席,用户必须输入缺席的结束日期和代表。 The TextBox for the representative have a AutoComplete that get Data from the Active Directory.
代表的文本框具有一个自动完成功能,该功能可以从Active Directory中获取数据。 And with a Image on the right side of the textbox, the user can search a representative in a Modal popup from jQuery.
并且在文本框的右侧有一个Image,用户可以在jQuery的Modal弹出窗口中搜索代表。 The Popup has one textbox and a imagebutton with a magnifying glass Symbol.
弹出窗口有一个文本框和一个带放大镜符号的图像按钮。 Now I want that if I click on this Symbol I get all found representative in a ListView in the PopUpBox with a fixed Width and Height.
现在,我希望如果单击此符号,我将在PopUpBox的ListView中找到所有具有固定宽度和高度的代表。
My Problem: 我的问题:
My PopUp open and I can set my Controls in the div block for this popupdialog. 我的弹出窗口打开,我可以在此弹出对话框的div块中设置控件。 I have create a Event for my ImageButton and generate the Code for this but if I click on the Button (in the popupdialog) the Code don't work.
我已经为我的ImageButton创建了一个Event并为此生成了代码,但是如果我单击Button(在弹出对话框中),则该代码不起作用。 It doesn't jump in the Button_click Method :(
它不会在Button_click方法中跳转:(
My Question: 我的问题:
How I can use the Controls in my popupdialog with jquery and asp.net? 如何在jquery和asp.net的popupdialog中使用控件?
Here my Code: 这是我的代码:
ASPX: (jquery code) ASPX:(jQuery代码)
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$("#dialogbox").dialog({
autoOpen: false,
modal: true,
resizable: false,
buttons: {
"OK": function () {
$(this).dialog("close");
},
"Cancel": function () {
$(this).dialog("close");
}
}
});
$("#imgVertreter").click(function () {
$("#dialogbox").dialog("open");
return false;
});
});
</script>
aspx: (my popupdialogbox div code) aspx :(我的popupdialogbox div代码)
<div id="dialogbox" title="Gesammte Vertreterliste">
<asp:TextBox ID="pVertreter" runat="server"></asp:TextBox>
<asp:ImageButton ID="pImageSearch" runat="server"
ImageUrl="~/App_Theme/lupe.jpg" Height="23px" Width="24px"
onclick="pImageSearch_Click" /><br />
<hr />
<asp:ListView runat="server" ID="ListView">
<LayoutTemplate>
<table id="UserTable" runat="server" border="0" width="100%" cellpadding="0" cellspacing="0">
<tr style="background-color:#ccdaeb" class="tableClass">
<th align="left" id="th4" runat="server"><asp:Label ID="lblName" runat="server" Text="Name, Vorname"></asp:Label></th>
<th align="left" id="th3" runat="server"><asp:Label ID="lblAbteilung" runat="server" Text="Abteilung"></asp:Label></th>
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td align="left"><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="lblFullname" Text='<%# Eval("Name") %>' runat="server"></asp:LinkButton></td>
<td align="left"><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="lblAbteil" Text='<%# Eval("Abteilung") %>' runat="server"></asp:LinkButton></td>
</tr>
</ItemTemplate>
<EmptyDataTemplate>
Es wurden keine Einträge gefunden
</EmptyDataTemplate>
<AlternatingItemTemplate>
<tr class="TableClass">
<td align="left"><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="lblFullname" Text='<%# Eval("Name") %>' runat="server"></asp:LinkButton></td>
<td align="left"><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="lblAbteil" Text='<%# Eval("Abteilung") %>' runat="server"></asp:LinkButton></td>
</tr>
</AlternatingItemTemplate>
</asp:ListView>
</div>
My C# Code for the imageButton (pImageSearch) 我的imageButton的C#代码(pImageSearch)
protected void pImageSearch_Click(object sender, ImageClickEventArgs e)
{
try
{
UserService srv = new UserService();
DataTable dt = srv.BenutzerFinden(Domain, pVertreter.Text);
DataView dv = new DataView(dt);
dv.Sort = "Nachname ASC";
this.ListView.DataSource = dv;
this.ListView.DataBind();
}
catch (Exception)
{
}
}
Here is a Picture from my Application : 这是我的应用程序中的图片:
Sourcecode in IE for my TestApplication that works! IE中适用于我的TestApplication的源代码有效!
<div id="dialog" title="Liste">
<input name="txtBox" type="text" value="rettet" id="txtBox" />
<input type="submit" name="btnEdit" value="übergeben" id="btnEdit" />
</div>
Sourcecode for my main Application that don't work! 我的主要应用程序的源代码不起作用!
<div id="dialogbox" title="Vertreterliste">
<input name="pVertreter" type="text" id="pVertreter" />
<input type="image" name="pImageSearch" id="pImageSearch" src="App_Theme/lupe.jpg" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("pImageSearch", "", true, "", "", false, false))" style="height:23px;width:24px;" /><br />
<input type="submit" name="suchen" value="suchen" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("suchen", "", true, "", "", false, false))" id="suchen" />
</div>
Why is here a onclick with a dopostback Oo? 为什么这里是带有dopostback Oo的onclick?
jQuery modals are created by cloning the DOM elements and placing them at the of the body tag. jQuery模态是通过克隆DOM元素并将其放置在body标签的来创建的。 This create valid DOM elements and it works fine on the client side.
这样可以创建有效的DOM元素,并且可以在客户端正常运行。
However for asp.net controls to send events, they must be inside the form tag(asp.net creates only one form tag). 但是,为使asp.net控件发送事件,它们必须位于表单标签内(asp.net仅创建一个表单标签)。
The solution is to create the dialog and then place the elements back into the form tag. 解决方案是创建对话框,然后将元素放回到form标签中。
$(document).ready(function () {
$("#dialogbox").dialog({
autoOpen: false,
modal: true,
resizable: false,
buttons: {
"OK": function () {
$(this).dialog("close");
},
"Cancel": function () {
$(this).dialog("close");
}
}
});
$("#dialogbox").parent().appendTo($("form:first"));
$("#imgVertreter").click(function () {
$("#dialogbox").dialog("open");
$("#dialogbox").parent().appendTo($("form:first"));
return false;
});
});
Your server events should now fire perfectly after that. 在此之后,您的服务器事件现在应该完美触发。
Use JavaScript like this: 像这样使用JavaScript:
(function(){
var popups = $('.js-popups');
popups.magnificPopup({
type:'inline',
midClick: true,
preloader: true,
fixedContentPos: false,
closeMarkup: '<span class="popup-close-ic mfp-close"></span>',
removalDelay: 300,
appendTo: 'form',
prependTo: 'form'
});
})();
Add the extra prependTo: 'form'
for form submission. 添加额外的
prependTo: 'form'
以提交表单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.