在模式弹出按钮单击事件,一个网格视图中没有发射 [英] Button click event on modal popup, inside a grid-view not firing
问题描述
我在遇到以下问题。
场景:
我有一个结合数据数列的ASP网格。最后一列已被转换为一个模板字段。在此模板场是与连接到它一个模式弹出扩展器的按钮。这个领域里面隐藏的是一个模式弹出。这种模式弹出来添加新帐户。它包含两个文本框,下拉列表和按钮(添加和取消)。当添加点击模态的新帐户在code后面插入后,应该关闭。
The scenario: I have a asp grid with a few columns that bind to data. The last column has been converted to a template-field. In this template-field is a button with a modal popup extender attached to it. Hidden inside this field is a modal popup. This modal popup is used to add a new account. it contains 2 text boxes, drop down lists and buttons("Add" and "Cancel"). When "add" is clicked the modal should close after the inserting of the new account in the code behind.
问题:
我得到显示和加载下拉从缓存列表,没有问题的弹出窗口。我如何获得按钮点击事件在$ C $丙火的后面。我已经使用执行_doPostBack('btnAddAcc','')的JavaScript函数尝试,但它一直返回错误JavaScript错误:预期的对象。我收集后,在谷歌约1个小时,这是因为btnAddAcc'没有发现,因为它实际上是网格视图单元格中,不能直接访问。使用页面方法和Ajax调用是不得已而为之的公司有对这种并有严格的政策,只有一堆手续后,允许这个。
The Problem: I get the popup to display and load the Drop down lists from the cache, without problem. How do I get the button click event to fire in the code behind. I've tried using a JavaScript function that performs a _doPostBack('btnAddAcc','') but it keeps returning the error "JavaScript error: Object expected". I gathered after about 1 hour on Google that it is because "btnAddAcc' is not found because it is actually within the grid-view cell and can't be directly accessed. Using page methods and ajax calls is a last resort as the company has a strict policy against this and only allowes this after a bunch of paperwork.
在code:
<asp:GridView ID="gvNEA" runat="server" CssClass="gridA_Orange"
AutoGenerateColumns="False" AllowPaging="True"
EmptyDataText="No transactions with 'Non Existent Account(s)'"
ShowHeaderWhenEmpty="True" Width="945px">
<Columns>
<asp:BoundField HeaderText="Transaction Date" DataField="Transaction_Date" />
<asp:BoundField HeaderText="Account Number" DataField="Account_Number" />
<asp:BoundField HeaderText="Description" DataField="Description"/>
<asp:BoundField HeaderText="Amount" DataField="Amount"/>
<asp:BoundField HeaderText="Offset Account" DataField="OffsetAccount" />
<asp:BoundField HeaderText="File Name" DataField="FileName" />
<asp:BoundField HeaderText="Transaction Type" DataField="TransType" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Button ID="btnAdd" runat="server" CausesValidation="false"
OnClientClick="showPopUp('pupAddAcc');" Text="Add Account" CssClass="ButtonStyle_Gray" />
<asp:ModalPopupExtender ID="mpeAddAcc" runat="server"
BackgroundCssClass="modalBackground" TargetControlID="btnAdd"
PopupControlID="pnlAddAcc"
CancelControlID="btnCancelAddAcc" DropShadow="True"
Enabled="True">
</asp:ModalPopupExtender>
<div id="pupAddAcc">
<asp:Panel ID="pnlAddAcc" runat="server" BackColor="White"
BorderColor="White" BorderStyle="Solid" BorderWidth="1px" Width="430">
<table align="center" id="tblAddAcc" class="BasicHTMLTable">
<asp:HiddenField ID="hfTransType" runat="server" Value='<%# Bind("TransType") %>' />
<tr align="center" >
<td colspan="2">
<asp:Label ID="lblAccountHeader" runat="server" width="390px" Text="Add Account"
CssClass="ButtonStyle_Orange" Height="25px" Font-Bold="true" Font-Size="Large" />
</td>
</tr>
<tr>
<td align="right" class="PopupCol">Account Number</td>
<td align="left" ><asp:Label ID="lblAccNumber" runat="server" Width="165px"
Text='<%# Bind("Account_Number") %>' /></td>
</tr>
<tr>
<td align="right" class="PopupCol" >Name</td>
<td align="left" ><asp:TextBox ID="txtName" runat="server" Width="165px" />
<asp:RequiredFieldValidator ID="rfvName" runat="server"
ControlToValidate="txtName" Text="*" ValidationGroup="acc" />
</td>
</tr>
<tr>
<td align="right" class="PopupCol" >Search Name</td>
<td align="left" ><asp:TextBox ID="txtSearchName" runat="server" Width="165px" />
<asp:RequiredFieldValidator ID="rfvSName" runat="server"
ControlToValidate="txtSearchName"
Text="*" ValidationGroup="acc" />
</td>
</tr>
<tr>
<td align="right" class="PopupCol" >Group</td>
<td align="left" >
<asp:DropDownList ID="ddlGroup" runat="server" Width="170">
</asp:DropDownList>
</td>
</tr>
<tr>
<td align="right" class="PopupCol" >Currency</td>
<td align="left" >
<asp:DropDownList ID="ddlCurrency" runat="server" Width="170px">
</asp:DropDownList>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:Button ID="btnAddAcc" runat="server" Text="Add Account"
CssClass="ButtonStyle_Orange" OnClientClick="javascript:addAccount()"
ValidationGroup="acc" />
  
<asp:Button ID="btnCancelAddAcc" runat="server" Text="Cancel" CssClass="ButtonStyle_Orange" />
</td>
</tr>
</table>
</asp:Panel>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="RecId" DataField="RecId" Visible="False"/>
</Columns>
我打开弹出这个JavaScript函数:
I open the popup with this JavaScript function:
function showPopUp(p) {
var Popup = document.getElementById(p);
Popup.style.visibility = "visible";
Popup.style.display = "";
}
点击btnAddAcc时,此功能:
The function when btnAddAcc is clicked:
function addAccount() {
_doPostBack('btnAddAcc', '');
};
背后的功能code
The code behind function
Protected Sub btnAddAcc_Click(sender As Object, e As System.EventArgs)
'Code for inserting new account goes here
End Sub
感谢您事先的任何帮助和建议。
问候
Thank you in advance for any help and proposals. Regards
推荐答案
我找到了答案,最终。我不得不使用gridview.RowCommand事件。它处理GridView的单元格内的所有按钮相关的事件。
I found the answer eventually. I had to use the gridview.RowCommand event. It handles all button related events inside a cell of a gridview.
看一看MSDN文档。这里需要解释一下最该命令的。
Have a look at the msdn documentation. It should explain most of this command.
问候乔治
这篇关于在模式弹出按钮单击事件,一个网格视图中没有发射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!