How to show modal pop Up on the click of a button within a datagrid.http://forums.asp.net/t/1197890.aspx/1?How+to+show+modal+pop+Up+on+the+click+of+a+button+within+a+datagrid+Wed, 26 Dec 2007 11:45:24 -050011978902076382http://forums.asp.net/p/1197890/2076382.aspx/1?How+to+show+modal+pop+Up+on+the+click+of+a+button+within+a+datagrid+How to show modal pop Up on the click of a button within a datagrid. <p>HI,</p> <p>I have a datagrid with Linkbuttons as the Template column.</p> <p>Also I have the Modal pop up extendar which will open a Panel. I have a button (display:none) as the TargetControl for the ModalPopupextendar.</p> <p>Now, on the click event of the Linkbutton in the datagrid, I have written the code to show ModalPopupextendar and it doesn't work.</p> <p>If I am using the control within the datagrid to show the modalpopupextendar will it work, or I have missed something to make it work.</p> <p>Can anybody help me on this?</p> <p>&nbsp;Please find my Code Below:</p> <p>-----ASPX Page-----------------------------------------------</p> <font size="2"> <p>&lt;%</font><font color="#008000" size="2">--&lt;Start&gt;Controls for Pop Up window--</font><font size="2">%&gt;</font><font color="#ff0000" size="2"></p> </font><font size="2"> <p></font><font color="#0000ff" size="2">&lt;</font><font color="#a31515" size="2">asp</font><font color="#0000ff" size="2">:</font><font color="#a31515" size="2">Button</font><font size="2"> </font><font color="#ff0000" size="2">ID</font><font color="#0000ff" size="2">=&quot;btnHiddenPopUpControl&quot;</font><font size="2"> </font><font color="#ff0000" size="2">runat</font><font color="#0000ff" size="2">=&quot;server&quot;</font><font size="2"> </font><font color="#ff0000" size="2">Text</font><font color="#0000ff" size="2">=&quot;Button&quot;</font><font size="2"> </font><font color="#ff0000" size="2">style</font><font color="#0000ff" size="2">=&quot;display:none&quot;</font><font size="2"> </font><font color="#0000ff" size="2">/&gt;</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">&lt;</font><font color="#a31515" size="2">cc1</font><font color="#0000ff" size="2">:</font><font color="#a31515" size="2">ModalPopupExtender</font><font size="2"> </font><font color="#ff0000" size="2">ID</font><font color="#0000ff" size="2">=&quot;mpeAssign&quot;</font><font size="2"> </font><font color="#ff0000" size="2">runat</font><font color="#0000ff" size="2">=&quot;server&quot;</p> </font><font size="2"></font><font color="#ff0000" size="2">TargetControlID</font><font color="#0000ff" size="2">=&quot;btnHiddenPopUpControl&quot;</font><font size="2"> </font><font size="2"> <p></font><font color="#ff0000" size="2">PopupControlID</font><font color="#0000ff" size="2">=&quot;pnlAssign&quot;</font><font size="2"> </font><font color="#ff0000" size="2">PopupDragHandleControlID</font><font color="#0000ff" size="2">=&quot;pnlHeaderAssign&quot;</p> </font><font size="2"></font><font color="#ff0000" size="2">Drag</font><font color="#0000ff" size="2">=&quot;true&quot;</font><font size="2"> </font><font color="#ff0000" size="2">OkControlID</font><font color="#0000ff" size="2">=&quot;btnOK&quot;</font><font size="2"> </font><font color="#ff0000" size="2">X</font><font color="#0000ff" size="2">=&quot;10&quot;</font><font size="2"> </font><font color="#ff0000" size="2">Y</font><font color="#0000ff" size="2">=&quot;10&quot;</font><font size="2"> </font><font color="#ff0000" size="2">RepositionMode</font><font color="#0000ff" size="2">=&quot;None&quot;&gt;</font><font size="2"> </font><font size="2"> <p></font><font color="#0000ff" size="2">&lt;/</font><font color="#a31515" size="2">cc1</font><font color="#0000ff" size="2">:</font><font color="#a31515" size="2">ModalPopupExtender</font><font color="#0000ff" size="2">&gt;</font><font size="2"></p> <p></font><font color="#0000ff"><font size="2">&lt;</font><font size="2">asp</font><font size="2">:</font></font><font color="#a31515" size="2">Panel</font><font size="2"> </font><font color="#ff0000" size="2">ID</font><font color="#0000ff" size="2">=&quot;pnlAssign&quot;</font><font size="2"> </font><font color="#ff0000" size="2">runat</font><font color="#0000ff" size="2">=&quot;server&quot;&gt;</p> </font><font size="2"> <p></font><font color="#0000ff"><font size="2">&lt;</font><font size="2">asp</font><font size="2">:</font></font><font color="#a31515" size="2">Panel</font><font size="2"> </font><font color="#ff0000" size="2">ID</font><font color="#0000ff" size="2">=&quot;pnlHeaderAssign&quot;</font><font size="2"> </font><font color="#ff0000" size="2">runat</font><font color="#0000ff" size="2">=&quot;server&quot;</font><font size="2"> </font><font color="#ff0000" size="2">style</font><font color="#0000ff" size="2">=&quot;cursor:move&quot;&gt;</font><font color="#0000ff" size="2">&lt;</font><font color="#a31515" size="2">div</font><font color="#0000ff" size="2">&gt;</font><font size="2">Pop Up</font><font color="#0000ff" size="2">&lt;/</font><font color="#a31515" size="2">div</font><font color="#0000ff" size="2">&gt;</font><font color="#0000ff" size="2">&lt;/asp</font><font color="#0000ff" size="2">:</font><font color="#a31515" size="2">Panel</font><font color="#0000ff" size="2">&gt;</font></p> <p><font size="2">This is the Pop Up window.</font><font color="#0000ff" size="2">&lt;asp:</font><font color="#a31515" size="2">Button</font><font size="2"> </font><font color="#ff0000" size="2">ID</font><font color="#0000ff" size="2">=&quot;btnOK&quot;</font><font size="2"> </font><font color="#ff0000" size="2">runat</font><font color="#0000ff" size="2">=&quot;server&quot;</font><font size="2"> </font><font color="#ff0000" size="2">Text</font><font color="#0000ff" size="2">=&quot;OK&quot;</font><font size="2"> </font><font color="#0000ff" size="2">/&gt;</font></p> <p><font color="#0000ff" size="2">&lt;/asp</font><font color="#0000ff" size="2">:</font><font color="#a31515" size="2">Panel</font><font color="#0000ff" size="2">&gt;</font></p> <p><font size="2">&lt;%</font><font color="#008000" size="2">--&lt;End&gt;Controls for Pop Up window</font><font size="2">&gt;</font></p> <font size="2"></font><font size="2"> <p class="MsoNormal" style="margin:0in 0in 0pt"><span style="font-size:10pt; color:blue; font-family:'Courier New'">&lt;</span><span style="font-size:10pt; color:#a31515; font-family:'Courier New'">asp</span><span style="font-size:10pt; color:blue; font-family:'Courier New'">:</span><span style="font-size:10pt; color:#a31515; font-family:'Courier New'">DataGrid</span><span style="font-size:10pt; font-family:'Courier New'"> <span style="color:red">ID</span><span style="color:blue">=&quot;dgAssignment&quot;</span> <span style="color:red"> runat</span><span style="color:blue">=&quot;server&quot; </span><span style="color:red">AllowPaging</span><span style="color:blue">=&quot;True&quot;</span> <span style="color:red">AutoGenerateColumns</span><span style="color:blue">=&quot;False&quot; </span><span style="color:red">Width</span><span style="color:blue">=&quot;900&quot;</span> <span style="color:red">Font-Size</span><span style="color:blue">=&quot;8pt&quot;</span> <span style="color:red"> CellPadding</span><span style="color:blue">=&quot;5&quot;</span> <span style="color:red">CellSpacing</span><span style="color:blue">=&quot;0&quot;</span> <span style="color:red">GridLines</span><span style="color:blue">=&quot;None&quot;</span> <span style="color:red"> BorderColor</span><span style="color:blue">=&quot;Black&quot;</span> <span style="color:red"> BorderWidth</span><span style="color:blue">=&quot;0px&quot;</span> <span style="color:red"> Font-Names</span><span style="color:blue">=&quot;Verdana&quot;</span> <span style="color:red"> OnItemDataBound</span><span style="color:blue">=&quot;dgAssignment_ItemDataBound&quot;&gt;</span></span></p> <span style="font-size:10pt; color:blue; font-family:'Courier New'">&lt;</span><span style="font-size:10pt; color:#a31515; font-family:'Courier New'">Columns</span><span style="font-size:10pt; color:blue; font-family:'Courier New'">&gt;</span><span style="font-size:10pt; color:blue; font-family:'Courier New'">&lt;</span><span style="font-size:10pt; color:#a31515; font-family:'Courier New'">asp</span><span style="font-size:10pt; color:blue; font-family:'Courier New'">:</span><span style="font-size:10pt; color:#a31515; font-family:'Courier New'">TemplateColumn</span><span style="font-size:10pt; font-family:'Courier New'"> <span style="color:red">HeaderText</span><span style="color:blue">=&quot;Status&quot;&gt;</span></span><span style="font-size:10pt; font-family:'Courier New'"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:blue">&lt;</span><span style="color:#a31515">itemtemplate</span><span style="color:blue">&gt;</span></span><span style="font-size:10pt; color:blue; font-family:'Courier New'">&lt;</span><span style="font-size:10pt; color:#a31515; font-family:'Courier New'"> asp</span><span style="font-size:10pt; color:blue; font-family:'Courier New'">:</span><span style="font-size:10pt; color:#a31515; font-family:'Courier New'">ImageButton</span><span style="font-size:10pt; font-family:'Courier New'"> <span style="color:red">id</span><span style="color:blue">=&quot;ibtnAssign&quot;</span> <span style="color:red"> runat</span><span style="color:blue">=&quot;server&quot;</span> <span style="">&nbsp;&nbsp;</span><span style="color:red">alternatetext</span><span style="color:blue">=&quot;Assign&quot;</span> <span style="color:#a31515">__designer</span><span style="color:blue">:</span><span style="color:red">wfdid</span><span style="color:blue">=&quot;w1&quot;</span> <span style="color:red">OnClick</span><span style="color:blue">=&quot;ibtnAssign_Click&quot;&gt;</span></span><span style="font-size:10pt; font-family:'Courier New'"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:blue">&lt;/</span><span style="color:#a31515"> asp</span><span style="color:blue">:</span><span style="color:#a31515">ImageButton</span><span style="color:blue">&gt;</span> </span><span style="font-size:10pt; color:blue; font-family:'Courier New'">&lt;/</span><span style="font-size:10pt; color:#a31515; font-family:'Courier New'">itemtemplate</span><span style="font-size:10pt; color:blue; font-family:'Courier New'">&gt;</span><span style="font-size:10pt; color:blue; font-family:'Courier New'">&lt;/</span><span style="font-size:10pt; color:#a31515; font-family:'Courier New'">asp</span><span style="font-size:10pt; color:blue; font-family:'Courier New'">:</span><span style="font-size:10pt; color:#a31515; font-family:'Courier New'">TemplateColumn</span><span style="font-size:10pt; color:blue; font-family:'Courier New'">&gt;</span><span style="font-size:10pt; color:blue; font-family:'Courier New'">&lt;/</span><span style="font-size:10pt; color:#a31515; font-family:'Courier New'">Columns</span><span style="font-size:10pt; color:blue; font-family:'Courier New'">&gt;</span> <p class="MsoNormal" style="margin:0in 0in 0pt"><span style="font-size:10pt; color:blue; font-family:'Courier New'">&lt;/</span><span style="font-size:10pt; color:#a31515; font-family:'Courier New'"> asp</span><span style="font-size:10pt; color:blue; font-family:'Courier New'">:</span><span style="font-size:10pt; color:#a31515; font-family:'Courier New'">DataGrid</span><span style="font-size:10pt; color:blue; font-family:'Courier New'">&gt;</span></p> </font> <p><font size="2">-----CodeBehind File------------------------------------</font></p> <font size="2"><span style="font-size:10pt; color:blue; font-family:'Courier New'">protected</span><span style="font-size:10pt; font-family:'Courier New'"> <span style="color:blue">void</span> ibtnAssign_Click(<span style="color:blue">object</span> sender, <span style="color:#2b91af">ImageClickEventArgs</span> e)</span><span style="font-size:10pt; font-family:'Courier New'"><span style="">&nbsp;&nbsp;&nbsp; </span>{<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:10pt; font-family:'Courier New'"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:blue">this</span>.mpeAssign.Show();</span> <p class="MsoNormal" style="margin:0in 0in 0pt"><span style="font-size:10pt; font-family:'Courier New'"><span style="">&nbsp;&nbsp;&nbsp; </span>}</span></p> <p>--------------------------------------------------------------------------------------------</p> </font> <p>Thanks,</p> <p>Gayathri.</p> 2007-12-25T11:38:22-05:002076607http://forums.asp.net/p/1197890/2076607.aspx/1?Re+How+to+show+modal+pop+Up+on+the+click+of+a+button+within+a+datagrid+Re: How to show modal pop Up on the click of a button within a datagrid. Hi, in this code u r passing btnhiddenPopupControl as a targetControlID. Insteed of passing btnhiddenPopupControl just pass that control id which is responsible to display popup. Such as u have taken a LinkButton named link1 within a gridview then u should pass link1 in TargetControlID of modalpopupextender control. 2007-12-25T17:29:58-05:002077388http://forums.asp.net/p/1197890/2077388.aspx/1?Re+How+to+show+modal+pop+Up+on+the+click+of+a+button+within+a+datagrid+Re: How to show modal pop Up on the click of a button within a datagrid. <p>Your source code is perfect.<br> But problem in ibtnAssign click event.<br> You can not directly access that button click event if button in gridview.<br> Instead of button click event, write code on Row_command event of gridview.<br> Just change your code as following code</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Gayathri_Bangalore</h4> <font color="#0000ff" size="2">&lt;</font><font color="#a31515" size="2">asp</font><font color="#0000ff" size="2">:</font><font color="#a31515" size="2">Button</font><font size="2"> </font><font color="#ff0000" size="2">ID</font><font color="#0000ff" size="2">=&quot;btnHiddenPopUpControl&quot;</font><font size="2"> </font><font color="#ff0000" size="2">runat</font><font color="#0000ff" size="2">=&quot;server&quot;</font><font size="2"> </font><font color="#ff0000" size="2">Text</font><font color="#0000ff" size="2">=&quot;Button&quot;</font><font size="2"> </font><font color="#ff0000" size="2">style</font><font color="#0000ff" size="2">=&quot;display:none&quot;</font><font size="2"> </font><font color="#0000ff" size="2">/&gt;</font></blockquote> <br> <br> No need to set TargetControlID as button and it display as none.<br> Instead of button, take one Label control and set it's ID as targetcontrolID<br> &lt;asp:Lable id=&quot;lblID&quot; runat=&quot;server&quot; /&gt;<br> &lt;cc1:ModalPopupExtender ID=&quot;mpeAssign&quot; runat=&quot;server&quot;<br> TargetControlID=&quot;lblID&quot; PopupControlID=&quot;pnlAssign&quot; PopupDragHandleControlID=&quot;pnlHeaderAssign&quot;<br> Drag=&quot;true&quot; OkControlID=&quot;btnOK&quot; X=&quot;10&quot; Y=&quot;10&quot; RepositionMode=&quot;None&quot;&gt;&lt;/cc1:ModalPopupExtender&gt;<br> <p></p> <p><br> </p> <blockquote><span class="icon-blockquote"></span> <h4>Gayathri_Bangalore</h4> <span style="font-size:10pt; font-family:'Courier New'"><span style="color:blue">&lt;</span><span style="color:rgb(163,21,21)">itemtemplate</span><span style="color:blue">&gt;</span></span><span style="font-size:10pt; color:blue; font-family:'Courier New'">&lt;</span><span style="font-size:10pt; color:rgb(163,21,21); font-family:'Courier New'"> asp</span><span style="font-size:10pt; color:blue; font-family:'Courier New'">:</span><span style="font-size:10pt; color:rgb(163,21,21); font-family:'Courier New'">ImageButton</span><span style="font-size:10pt; font-family:'Courier New'"> <span style="color:red">id</span><span style="color:blue">=&quot;ibtnAssign&quot;</span> <span style="color:red"> runat</span><span style="color:blue">=&quot;server&quot;</span> <span style="">&nbsp;&nbsp;</span><span style="color:red">alternatetext</span><span style="color:blue">=&quot;Assign&quot;</span> <span style="color:rgb(163,21,21)">__designer</span><span style="color:blue">:</span><span style="color:red">wfdid</span><span style="color:blue">=&quot;w1&quot;</span> <span style="color:red">OnClick</span><span style="color:blue">=&quot;ibtnAssign_Click&quot;&gt;</span></span><span style="font-size:10pt; font-family:'Courier New'"><span style=""></span><span style="color:blue">&lt;/</span><span style="color:rgb(163,21,21)"> asp</span><span style="color:blue">:</span><span style="color:rgb(163,21,21)">ImageButton</span><span style="color:blue">&gt;</span> </span><span style="font-size:10pt; color:blue; font-family:'Courier New'">&lt;/</span><span style="font-size:10pt; color:rgb(163,21,21); font-family:'Courier New'">itemtemplate</span><span style="font-size:10pt; color:blue; font-family:'Courier New'">&gt;</span></blockquote> <p></p> <p>&lt;itemtemplate&gt;<br> &lt; asp:ImageButton id=&quot;ibtnAssign&quot; runat=&quot;server&quot;&nbsp;&nbsp; alternatetext=&quot;Assign&quot; <b>CommandName=&quot;ShowModelPopUp&quot;</b>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> &lt;/ asp:ImageButton&gt;<br> <u><i><br> On Row_command event of gridview,write this code</i></u></p> <p><u><i></i></u><br> if(e.CommandName==&quot;ShowModelPopUp&quot;)<br> {<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; this.mpeAssign.Show();<br> } <br> </p> 2007-12-26T10:22:02-05:002077456http://forums.asp.net/p/1197890/2077456.aspx/1?Re+How+to+show+modal+pop+Up+on+the+click+of+a+button+within+a+datagrid+Re: How to show modal pop Up on the click of a button within a datagrid. <p>Looks like you are already handling the ItemDataBound event of the DataGrid, so attach the event there:</p> <p>private void dgAssignment_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)<br> {&nbsp;&nbsp;&nbsp;<br> &nbsp;ListItemType listItemType = e.Item.ItemType;</p> <p>&nbsp;if ( (listItemType == ListItemType.AlternatingItem) || (listItemType == ListItemType.Item) )<br> &nbsp;{<br> &nbsp;&nbsp;ImageButton imageButton = (ImageButton)e.Item.FindControl(&quot;ibtnAssign&quot;);</p> <p>&nbsp;&nbsp;if ( imageButton != null )<br> &nbsp;&nbsp;{<br> &nbsp;&nbsp;&nbsp;imageButton.Click &#43;= new System.Web.UI.ImageClickEventHandler(this.ibtnAssign_Click);<br> &nbsp;&nbsp;}<br> &nbsp;}<br> }</p> <p>NC...<br> </p> 2007-12-26T11:45:24-05:00