我正在将一个外部文件'contact_us.aspx'加载到jquery对话框中。外部页面包含一个表单。
按下提交按钮后,它会关闭对话框并将页面更改为contact_us.aspx。是我的代码是正确的还是有不同的方式这样做。看下面的代码,谢谢。
这个JS在y主页中:
<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>
单击链接时加载到对话框中的外部文件“contact_us.aspx”。
<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>
文件后面的代码:
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 = "mark@clickfire.co.uk";
myMail.From = "mark@yahoo.com";
//myMail.Bcc = "client@clickfire.biz";
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;
}
答案 0 :(得分:0)
固定。傻我。
//pnlEnquiry.Visible = false;
//pnlThanks.Visible = true;
Response.Redirect("~/default.aspx");