I am loading an external file 'contact_us.aspx' into a jquery dialog box. the external page contains a form.
When the submit button is pressed it closes the dialog box and changes the page to contact_us.aspx. is my code correct or is there a different way of doing this. see my code below, thanks.
This JS is in y masterpage:
<script type="text/javascript">
$(document).ready(function() {
var dialogOpts = {
modal:
true,
bgiframe:
true,
autoOpen: false,
height: 500,
width: 500,
open: function(type, data) {
$(this).parent().appendTo(jQuery("form:first"));
}
}
$("#genericContact").dialog(dialogOpts); //end dialog
$('a.conactGeneric').click(
function() {
$("#genericContact").load("contact_us.aspx", [], function() {
$("#genericContact").dialog("open");
}
);
return false;
}
);
});
</script>
The external file 'contact_us.aspx' which is loaded into the dialog box, when the link is clicked.
<asp:Panel ID="pnlEnquiry" runat="server" DefaultButton="btn_Contact">
<asp:Label ID="lblError" CssClass="error" runat="server" Visible="false" Text=""></asp:Label>
<div class="contact_element">
<label for="txtName">Your Name <span>*</span></label>
<asp:TextBox CssClass="contact_field" ID="txtName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator CssClass="contact_error" ControlToValidate="txtName" Display="Dynamic" ValidationGroup="valContact" ID="RequiredFieldValidator1" runat="server" ErrorMessage="Enter your name"></asp:RequiredFieldValidator>
</div>
<div class="contact_element">
<label for="txtName">Phone Number</label>
<asp:TextBox CssClass="contact_field" ID="txtTel" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator CssClass="contact_error" ControlToValidate="txtTel" Display="Dynamic" ValidationGroup="valContact" ID="RequiredFieldValidator2" runat="server" ErrorMessage="Enter your phone number"></asp:RequiredFieldValidator>
</div>
<div class="contact_element">
<label for="txtEmail">Your Email <span>*</span></label>
<asp:TextBox CssClass="contact_field" ID="txtEmail" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator CssClass="contact_error" ControlToValidate="txtEmail" Display="Dynamic" ValidationGroup="valContact" ID="RequiredFieldValidator3" runat="server" ErrorMessage="Enter your email address"></asp:RequiredFieldValidator>
</div>
<div class="contact_element">
<label for="txtQuestion">Question <span>*</span></label>
<asp:TextBox TextMode="MultiLine" CssClass="contact_question" ID="txtQuestion" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator CssClass="contact_error" ControlToValidate="txtQuestion" Display="Dynamic" ValidationGroup="valContact" ID="RequiredFieldValidator4" runat="server" ErrorMessage="Enter your question"></asp:RequiredFieldValidator>
</div>
<div class="contact_chkbox">
<asp:CheckBox ID="chkNews" runat="server" Checked="
true" Text="Receive our monthly newsletter" EnableTheming="false" />
</div>
<span class="mandatory">* Required Field</span>
<asp:LinkButton ID="btn_Contact" ToolTip="Submit" CssClass="submit_btn" ValidationGroup="valContact" runat="server" OnClick="SignUp" ></asp:LinkButton>
<asp:RegularExpressionValidator CssClass="contact_error" ID="RegularExpressionValidator1" runat="server" ValidationExpression=".*@.{2,}\..{2,}" Display="Dynamic" ValidationGroup="valContact" ControlToValidate="txtEmail" ErrorMessage="Invalid email format."></asp:RegularExpressionValidator>
<asp:ValidationSummary ID="ValidationSummary1" ValidationGroup="valContact" ShowMessageBox=true ShowSummary=false runat="server" />
</asp:Panel>
<asp:Panel ID="pnlThanks" runat="server" Visible="false">
<h1>Thank you!</h1>
</asp:Panel>
code behind file:
protected void SignUp(object sender, EventArgs e)
{
SmtpMail.SmtpServer = "localhost";
MailMessage myMail = new MailMessage();
//String myToEmail = MyDB.getScalar("select setting_value from [Website.Settings]"); ;
//myMail.To = myToEmail;
myMail.To = "
[email protected]";
myMail.From = "
[email protected]";
//myMail.Bcc = "
[email protected]";
myMail.Subject = "Enquiry from the Naturetrek Site";
StringBuilder myContent = new StringBuilder();
myContent.Append("Name : " + txtName.Text + "\r\n");
myContent.Append("Email: " + txtEmail.Text + "\r\n");
myContent.Append("Telephone: " + txtTel.Text + "\r\n");
myContent.Append("\r\nTheir Question: \r\n" + txtQuestion.Text + "\r\n");
if (chkNews.Checked != true)
{
myContent.Append("Subscribed to newsletter: No");
}
else
{
myContent.Append("Subscribed to newsletter: Yes");
}
myContent.Append("\r\n");
myMail.Body = myContent.ToString();
SmtpMail.Send(myMail);
pnlEnquiry.Visible = false;
pnlThanks.Visible = true;
}