Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Just started using JQuery Mobile and I am having trouble sending email. I use ASP.NET Forms and generally use a submit button to call the SmtpClient() and send the email. This apparently does not mesh with AJAX and I cannot send the email without setting the data-ajax="false". Setting the data-ajax to false, however, makes the rest of the page nonfunctional.

I understand that ASP.NET Forms is not ideal for JQuery Mobile but does anybody know a workaround? Like disabling AJAX to send the message then reenabling it after the message has been sent; or something jerry-rigged like that?

Here's an example:

ASP.NET
<asp:TextBox ID="tbxRFQName" runat="server" Text="Contact Name" ForeColor="Gray" Font-Italic="true"></asp:TextBox>
                            <asp:TextBox ID="tbxRFQCompany" runat="server" Text="Company Name" ForeColor="Gray" Font-Italic="true"></asp:TextBox>   
                            <asp:TextBox ID="tbxRFQPhone" runat="server" Text="Phone Number" ForeColor="Gray" Font-Italic="true"></asp:TextBox>                          
                            <asp:TextBox ID="tbxRFQEmail" runat="server" Text="Email Address" ForeColor="Gray" Font-Italic="true"></asp:TextBox> 
                            <asp:DropDownList ID="ddlRFQ" runat="server">
                                <asp:ListItem Selected="True" Value="select">SELECT</asp:ListItem>
                                <asp:ListItem Value="1">1</asp:ListItem>
                                <asp:ListItem Value="2">2</asp:ListItem>
                                <asp:ListItem Value="3">3</asp:ListItem>
                                <asp:ListItem Value="4">4</asp:ListItem>
                                <asp:ListItem Value="5">5</asp:ListItem>
                                <asp:ListItem Value="6">6</asp:ListItem>
                                <asp:ListItem Value="other">7</asp:ListItem>                                    
                            </asp:DropDownList>                            
                            <asp:TextBox ID="tbxRFQMessage" runat="server" TextMode="MultiLine" Text="Message" ForeColor="Gray" Font-Italic="true"></asp:TextBox>
                            <br />
                            <asp:Button ID="btnRFQSubmit" runat="server" Text="SUBMIT" onclick="btnRFQSubmit_Click"/>

C#
protected void btnRFQSubmit_Click(object sender, EventArgs e)
    {
        if (Page.IsValid == true)
        {
            string fileName = Server.MapPath("~/App_Data/rfqglobal.txt");
            string mailBody = File.ReadAllText(fileName);

            mailBody = mailBody.Replace("##Noun##", ddlRFQ.SelectedValue);
            mailBody = mailBody.Replace("##Name##", tbxRFQName.Text);
            mailBody = mailBody.Replace("##Company##", tbxRFQCompany.Text);
            mailBody = mailBody.Replace("##Phone##", tbxRFQPhone.Text);
            mailBody = mailBody.Replace("##Email##", tbxRFQEmail.Text);
            mailBody = mailBody.Replace("##Message##", tbxRFQMessage.Text);

            MailMessage message = new MailMessage();
            message.Subject = "Request for Quote";
            message.Body = mailBody;

            message.From = new MailAddress("email@email.com", "email");
            message.To.Add(new MailAddress("email@email.com", "email"));

            SmtpClient productSmtpClient = new SmtpClient();
            productSmtpClient.Send(message);

            tbxRFQName.Text = "";
            tbxRFQCompany.Text = "";
            tbxRFQPhone.Text = "";
            tbxRFQEmail.Text = "";
            tbxRFQMessage.Text = "";

        }
    }
Posted
Comments
[no name] 31-Oct-15 1:01am    
Use try-catch block to catch exact exception message. And after getting exception message you can google it or add here by improving your question.

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