Note that there are some explanatory texts on larger screens.

plurals
  1. POButton click event on modal popup, inside a grid-view not firing
    primarykey
    data
    text
    <p>I'm having problems with the following.</p> <p><strong>The scenario:</strong> 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.</p> <p><strong>The Problem:</strong> 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.</p> <p>The Code:</p> <pre><code>&lt;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"&gt; &lt;Columns&gt; &lt;asp:BoundField HeaderText="Transaction Date" DataField="Transaction_Date" /&gt; &lt;asp:BoundField HeaderText="Account Number" DataField="Account_Number" /&gt; &lt;asp:BoundField HeaderText="Description" DataField="Description"/&gt; &lt;asp:BoundField HeaderText="Amount" DataField="Amount"/&gt; &lt;asp:BoundField HeaderText="Offset Account" DataField="OffsetAccount" /&gt; &lt;asp:BoundField HeaderText="File Name" DataField="FileName" /&gt; &lt;asp:BoundField HeaderText="Transaction Type" DataField="TransType" /&gt; &lt;asp:TemplateField ShowHeader="False"&gt; &lt;ItemTemplate&gt; &lt;asp:Button ID="btnAdd" runat="server" CausesValidation="false" OnClientClick="showPopUp('pupAddAcc');" Text="Add Account" CssClass="ButtonStyle_Gray" /&gt; &lt;asp:ModalPopupExtender ID="mpeAddAcc" runat="server" BackgroundCssClass="modalBackground" TargetControlID="btnAdd" PopupControlID="pnlAddAcc" CancelControlID="btnCancelAddAcc" DropShadow="True" Enabled="True"&gt; &lt;/asp:ModalPopupExtender&gt; &lt;div id="pupAddAcc"&gt; &lt;asp:Panel ID="pnlAddAcc" runat="server" BackColor="White" BorderColor="White" BorderStyle="Solid" BorderWidth="1px" Width="430"&gt; &lt;table align="center" id="tblAddAcc" class="BasicHTMLTable"&gt; &lt;asp:HiddenField ID="hfTransType" runat="server" Value='&lt;%# Bind("TransType") %&gt;' /&gt; &lt;tr align="center" &gt; &lt;td colspan="2"&gt; &lt;asp:Label ID="lblAccountHeader" runat="server" width="390px" Text="Add Account" CssClass="ButtonStyle_Orange" Height="25px" Font-Bold="true" Font-Size="Large" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="right" class="PopupCol"&gt;Account Number&lt;/td&gt; &lt;td align="left" &gt;&lt;asp:Label ID="lblAccNumber" runat="server" Width="165px" Text='&lt;%# Bind("Account_Number") %&gt;' /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="right" class="PopupCol" &gt;Name&lt;/td&gt; &lt;td align="left" &gt;&lt;asp:TextBox ID="txtName" runat="server" Width="165px" /&gt; &lt;asp:RequiredFieldValidator ID="rfvName" runat="server" ControlToValidate="txtName" Text="*" ValidationGroup="acc" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="right" class="PopupCol" &gt;Search Name&lt;/td&gt; &lt;td align="left" &gt;&lt;asp:TextBox ID="txtSearchName" runat="server" Width="165px" /&gt; &lt;asp:RequiredFieldValidator ID="rfvSName" runat="server" ControlToValidate="txtSearchName" Text="*" ValidationGroup="acc" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="right" class="PopupCol" &gt;Group&lt;/td&gt; &lt;td align="left" &gt; &lt;asp:DropDownList ID="ddlGroup" runat="server" Width="170"&gt; &lt;/asp:DropDownList&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="right" class="PopupCol" &gt;Currency&lt;/td&gt; &lt;td align="left" &gt; &lt;asp:DropDownList ID="ddlCurrency" runat="server" Width="170px"&gt; &lt;/asp:DropDownList&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="center" colspan="2"&gt; &lt;asp:Button ID="btnAddAcc" runat="server" Text="Add Account" CssClass="ButtonStyle_Orange" OnClientClick="javascript:addAccount()" ValidationGroup="acc" /&gt; &amp;nbsp&amp;nbsp &lt;asp:Button ID="btnCancelAddAcc" runat="server" Text="Cancel" CssClass="ButtonStyle_Orange" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/asp:Panel&gt; &lt;/div&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:BoundField HeaderText="RecId" DataField="RecId" Visible="False"/&gt; &lt;/Columns&gt; </code></pre> <p></p> <p>I open the popup with this JavaScript function:</p> <pre><code>function showPopUp(p) { var Popup = document.getElementById(p); Popup.style.visibility = "visible"; Popup.style.display = ""; } </code></pre> <p>The function when btnAddAcc is clicked:</p> <pre><code>function addAccount() { _doPostBack('btnAddAcc', ''); }; </code></pre> <p>The code behind function</p> <pre><code>Protected Sub btnAddAcc_Click(sender As Object, e As System.EventArgs) 'Code for inserting new account goes here End Sub </code></pre> <p>Thank you in advance for any help and proposals. Regards</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload