coder
coder

Reputation: 13248

Button Click automatically not triggering

I have a button,Linkbutton and an ModalPopup.

If I click button1 I need to click 2nd button automatically and Launch ModalPopup.But it's not triggering at all.

Can anyone say me where am I going wrong?

This is my ModalPopup:

     <asp:UpdatePanel ID="UpdatePanel2" runat="server">
            <ContentTemplate>
                <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="LinkButton1"
                    PopupControlID="Panel1" BackgroundCssClass="modalBackground" DropShadow="False"
                    CancelControlID="CancelButton" />
                <asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" Style="display: none;
                    width: 300px;">
                    <asp:HyperLink ID="DownloadLink" runat="server" ForeColor="#0066FF">Download</asp:HyperLink>
                    <asp:Button ID="CancelButton" CssClass="btn-blue" runat="server" Text="Cancel" />
                    <asp:Button ID="button1" runat="server" Text="Select Image" Style="position: absolute;
                    left: 400px; top: 500px; z-index: 99;"/>
                <asp:LinkButton ID="LinkButton1" OnClick="LinkButton1_Click" runat="server" Visible="true"
                    Style="position: absolute; left: 620px; top: 500px; z-index: 99;">Close</asp:LinkButton>                
               </asp:Panel>

                <br />
            </ContentTemplate>
    </asp:UpdatePanel>

This is my code-behind:

1st Button:

Protected Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click

Linkbutton1_Click(Nothing,Nothing)

End Sub

2nd Button:

Protected Sub Linkbutton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles 
Linkbutton1.Click

ModalPopupExtender1.Show

End Sub

Upvotes: 0

Views: 1461

Answers (2)

James Johnson
James Johnson

Reputation: 46077

Unless there's something I'm missing, the approach you're using seems unnecessarily complicated. Just create a method that opens the dialog, and you can call it anywhere...

protected void LinkButton1_Click(object sender, EventArgs e)
{
    //perform whatever logic you need

    //open the dialog
    ShowDialog();
}

protected void Button1_Click(object sender, EventArgs e)
{
    //perform whatever logic you need

    //open the dialog
    ShowDialog();
}

private void ShowDialog()
{
    ModalPopupExtender1.Show();
}

Upvotes: 1

Adam
Adam

Reputation: 3665

Give this a try. For code within the first button click.

Linkbutton1_Click(sender, New System.EventArgs())

Upvotes: 0

Related Questions