Click here to Skip to main content
15,905,616 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I am trying to open a ModalPopup on GridView LinkButton, but when I am giving LinkButton ID to targetcontrolid of pop up, it is not accepting.

Please help me.
XML
<asp:GridView ID="grdView" runat="server" AutoGenerateColumns="False" CellPadding="0"
            ForeColor="#333333" GridLines="None" onrowdatabound="grdView_RowDataBound">
    <Columns>
        <asp:TemplateField HeaderText="Dr. Photo">
            <ItemTemplate>
                <asp:Image ID="Image1" runat="server" Style="height: 80px; width: 100px;" ImageUrl='<%#  String.Format("~/Upload/Docters/" + Eval("ImgName")) %>' />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150px" >
        <ItemStyle Width="150px"></ItemStyle>
        </asp:BoundField>
        
        <asp:BoundField DataField="Qualification" HeaderText="Qualification"
            ItemStyle-Width="50px" >
        <ItemStyle Width="50px"></ItemStyle>
        </asp:BoundField>
        <asp:TemplateField HeaderText="Click to Contact">
        <ItemTemplate>
        <asp:LinkButton ID="popup" runat="server" Text="Click to Contact"></asp:LinkButton>
        </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

<ajaxToolKit:ModalPopupExtender id="ModalPopupExtender1" runat="server"
    cancelcontrolid="btncancel" okcontrolid="btnSend"
    targetcontrolid="Button1" popupcontrolid="Panel1"
    popupdraghandlecontrolid="PopupHeader" drag="true" backgroundcssclass="ModalPopupBG">
</ajaxToolKit:ModalPopupExtender
Posted
v4
Comments
Glad to know my answer helped you. Thanks... :)
Mohd Arif Khan 24-Sep-13 2:55am    
yeah, thanks a lot :)
Most welcome. :)

Refer
ModalPopUpExtender In GridView[^].

Solution
According to the codes in above article, your ModalPopUp should be like...
ASP.NET
<AjaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" 
                                runat="server"
                                TargetControlID="Button1"
                                PopupControlID="Panel1"
                                PopupDragHandleControlId="PopupHeader"
                                BackgroundCssClass="ModalPopupBG"
                                OkControlID="btnSend"
                                CancelControlId="btncancel"
                                Drag="true">
</AjaxToolkit:ModalPopupExtender>

Here there is no need to specify the LinkButton.

Attach an OnClick Event to LinkButton.
XML
<asp:LinkButton ID="popup" runat="server" Text="Click to Contact" OnClick="popup_Click"></asp:LinkButton>

Define that Event on Code Behind like...
C#
protected void popup_Click(object sender, EventArgs e)
{
    // Other Codes.

    // Show ModalPopUpExtender.
    ModalPopupExtender1.Show();
}
 
Share this answer
 
v3
Comments
U_Hanisa 9-Oct-14 3:27am    
Where is your Button1,sorry my screen cannot run. Then the code behind for popup_Click, where is the object. I can't get it. TQ :)
Button1, you need to declare. And what object you are referring to?
First, take a button in a div tag as shown below.
XML
<div style="visibility:hidden">
<asp:Button id="btnSample" runat="server"/>
</div>


Now in the gridview we use the Commandfields to display the Edit,Update cancel button
XML
<asp:CommandField ButtonType="Button" ShowEditButton="true" ShowCancelButton="true"
                       EditText="Select" UpdateText="Update" CancelText="Cancel" HeaderText="Confirm">
                       <HeaderStyle Font-Size="Smaller" Font-Bold="true" HorizontalAlign="Left" Width="45%" />
                       <ItemStyle Font-Size="Smaller" HorizontalAlign="Left" Width="45%" />
                   </asp:CommandField>


Next, we assign the targetcontrolid of MPE equal to the button hidden in div tag.

XML
<ajax:ModalPopupExtender ID="MPEAward" runat="server" TargetControlID="btnSample" PopupControlID="pnlSave"
    BackgroundCssClass="modalBackground" DropShadow="true" CancelControlID="btnCancel"
    Drag="true">
</ajax:ModalPopupExtender>


In the code behind

In gridview rowdatabound, we find the Update button present in gridview and invoke a javascript ShowPopUp()
if (e.Row.RowType == DataControlRowType.DataRow)
           {
               if ((e.Row.RowState & DataControlRowState.Edit) > 0)
               {
                   Button btnUpdate = (Button)e.Row.Cells[6].Controls[0];
 
                   btnUpdate.OnClientClick = "return ShowPopup();";
 

               }
           }


In Javascript,

C#
function ShowPopup() {

        $('#<%= btnSample.ClientID %>').click();
        return false;
    }


Finally, the page needs to return false in the javascript so as to make the modalpopup present on the page.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900