简体   繁体   中英

asp.net LinkButton in javascript not getting called when trying to send mail

         <div class="popup" id="invite-box">
       <asp:UpdatePanel ID="upd1" runat="server">
       <ContentTemplate>
            <a href="#" class="close">close</a>
            <div class="popup-holder">
                <div class="popup-frame">
                    <div class="container"> 
                        <div action="#" class="invite-form" >


                                        <div class="email">
                                            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></div>

                                        <div class="textarea">
                                            <div class="textarea-holder">
                                                <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Rows="10" Columns="30"></asp:TextBox>
                                            </div>
                                        </div>

                                <div class="btn-holder">
                                    <a href="#" class="btn-view">View sample e-mail</a>
                                    <asp:LinkButton ID="LinkButton6" runat="server" CssClass="btn-send" 
                                        onclick="LinkButton6_Click"></asp:LinkButton>
                                </div>


                    </div>
                </div>
</div>
</div>
        </ContentTemplate>
        </asp:UpdatePanel>
        </div>

This is my pop up code and i am trying to send a mail on linkbutton click however the LinkButton_Click does not get called in the code behind

My code behind is as follows:

    protected void LinkButton6_Click(object sender, EventArgs e) // Not getting called
{
    if (r1.Checked == true)
    {

        try
        {
            MailMessage mail = new MailMessage();
            mail.Subject = "Some one has invited you: Join abc! Meet ## of %%";
            mail.Body = mee.data[0].name+"</br>"+TextBox1.Text;
            mail.To.Add(TextBox2.Text);

            ////send the message

            SmtpClient mySmtpClient = new SmtpClient();
            System.Net.NetworkCredential myCredential = new System.Net.NetworkCredential("****", "*****");
            //mySmtpClient.Port="25";
            mySmtpClient.Host = "abc";
            mySmtpClient.UseDefaultCredentials = false;
            mySmtpClient.Credentials = myCredential;
            mySmtpClient.Send(mail);
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }

EDIT:

i think my code is considering the linkbutton as javascript Button在此处输入图像描述

Thanks

I Think your missing triggers in update panel. add below triggers in just before closing tag of update panel

<Triggers>                      
    <asp:AsyncPostBackTrigger ControlID="LinkButton6" EventName="Click" />
</Triggers>
</asp:UpdatePanel> 

Hope this may help...

From looking at your question...

I would say that the link button you are showing is not the same as the link button in the source.

I tried to replicate your issue with a link button that had Invite as its text

<asp:LinkButton ID="LinkButton6" runat="server" onclick="LinkButton6_Click">Invite</asp:LinkButton>

You can see in the source it contains Invite between the tags.

In your source there is no mention of Invite

<asp:LinkButton ID="LinkButton6" runat="server" CssClass="btn-send"                                             onclick="LinkButton6_Click"></asp:LinkButton>  

Try adding another Link button, double click on it, add your code to it and try again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM