[英]Form submit (email) with ASP.net and jQuery not working
我正在嘗試解決這個問題,但是運氣不佳。
基本上,我有一個使用jQuery表單向導插件構建的向導樣式HTML表單,其中包括jQuery.Form,jQuery.Validation和jQuery.History插件。 我正在嘗試使用ASP.net Web表單提交電子郵件,但似乎根本無法使它工作。
這是我的標記和代碼的示例:
<form id="form1" runat="server">
<div class="step" id="step01">
<input type="text" id="text1" name="text1" runat="server" /><br />
<input type="text" id="text2" name="text2" runat="server" />
</div>
<div class="step" id="step02">
<input type="text" id="text3" name="text3" runat="server" /><br />
<input type="text" id="text4" name="text4" runat="server" />
</div>
<input type="reset" id="reset" value="Reset" />
<asp:Button runat="server" id="submit" Text="Submit" OnClick="button_Click" />
</form>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
public partial class email_test02 : System.Web.UI.Page
{
protected void button_Click(object sender, EventArgs e)
{
//create the mail message
MailMessage mail = new MailMessage();
//set the addresses
mail.From = new MailAddress("test@test.com");
mail.To.Add("test2@test.com");
//set the content
mail.Subject = "Test";
mail.Body =
text1.Value + text2.Value + text3.Value + text4.Value;
//send the message
SmtpClient smtp = new SmtpClient("Localhost");
smtp.Send(mail);
}
}
我不確定從這里開始需要做什么。 我對jQuery還是個新手,對ASP.net還是個新手,所以我確定我只是缺少一些明顯的東西,但是我所做的任何事情都沒有運氣。 因此,如果有人可以在這里指出正確的方向,將不勝感激。
如果您使用jquery表單進行提交,請刪除onclick並為表單提供一個ID。 該ID進入頁面上您的javascript代碼中以收集您的帖子。
<script type="text/javascript">
$(document).ready(function() {
$('#form1').ajaxForm(function() {
location.href=("submitted.aspx");
});
});
</script>
在頁面加載中只需添加
if(isPostback){
string txt1 = Request["text1"];
// you will want to clean this string, (encode for storage)
// and maybe also check for isnull or empty first i.e
var username = !string.IsNullorEmpty(Request["text1"]) ? Request["text1"] : null;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.