【发布时间】:2015-01-29 10:24:15
【问题描述】:
我有一个带有提交按钮的 html 表单,其中包含姓名、电子邮件、联系方式和反馈字段。
我的html表单代码是
<div class="feedback">
<a id="feedback_button">Feedback</a>
<form method="post" action="http://localhost:12459/WebsiteForm/WebSiteFeedbackProcessing.aspx"
name="new_post">
<div class="form">
<div>
<div>
<input type="text" class="text_field" id="fname" name="fname" placeholder="First Name"
style="margin-bottom: 3px; width: 50%;" maxlength="20" />
</div>
<div>
<input type="text" class="text_field" id="email" name="email" placeholder="Email"
style="margin-bottom: 3px; width: 50%;" maxlength="30" />
</div>
<div>
<input type="text" class="text_field" id="contact" name="contact" placeholder="Contact No"
style="margin-bottom: 3px; width: 50%;" maxlength="15" />
</div>
<textarea id="feedback" name="feedback" placeholder="feedback" style="min-height: 41px;
width: 48%;" maxlength="100" rows="" cols=""></textarea>
</div>
<input type="submit" value="Send" class="sendfeedback" />
</div>
</form>
</div>
我正在将这四个值保存到 sql server 数据库中。
点击提交按钮后,表单进入另一个asp.net c#项目(代码如下)进行数据保存。 这里通过函数SaveFeedback,它以整数值的形式返回结果,1表示成功,0表示失败。
我的代码是
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Data;
using CorporateOnlineTest.BAL;
using System.Text;
namespace CorporateOnlineTest.Web.WebsiteForm {
public partial class WebSiteFeedbackProcessing: System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
string fname = "";
string contact = "";
string email = "";
string feedback = "";
for (int i = 0; i < Request.Form.AllKeys.Length; i++) {
string key = Request.Form.AllKeys[i] + "";
string value = Request.Form[i];
if (key + "" == "fname") {
fname = value;
} else if (key + "" == "contact") {
contact = value;
} else if (key + "" == "email") {
email = value;
} else if (key + "" == "feedback") {
feedback = value;
}
}
//Insert in database and send mail.
if (Request.Form.AllKeys.Length > 0) {
int Submit;
SubAdminBAL objSubadmin = new SubAdminBAL();
Submit = SaveFeedback(fname, contact, email, feedback);
if (Submit == 1) {
ScriptManager.RegisterStartupScript(this, this.GetType(),
"alert",
"alert('Your Feedback Has Been Sent Successfully!');window.location ='http://localhost:2421/Psychometricachat_ByKaustubh/p/online-managerial-skill-test.html';",
true);
} else {
ScriptManager.RegisterStartupScript(this, this.GetType(),
"alert",
"alert('Please Try Again!');window.location ='http://localhost:2421/Psychometricachat_ByKaustubh/p/online-managerial-skill-test.html';",
true);
}
}
}
[WebMethod]
public int SaveFeedback(string fname, string contact, string email, string feedback) {
int Result = 0;
SubAdminBAL bl = new SubAdminBAL();
Result = Convert.ToInt32(bl.SaveWebsiteFeedbackBAL(fname, contact, email, feedback));
return Result;
}
}
}
我想在我的 html 页面上显示这些消息而不重新加载该页面。
我尝试了很多选项,但每次我的页面在消息显示之前或之后重新加载。
有没有人有解决办法。请尽早恢复。
提前致谢
【问题讨论】:
-
我认为您正在寻找 AJAX。
-
请添加你的js代码。为此,您需要使用 ajax 调用。
-
用javascript提交表单并通过ajax将表单数据发送到服务器
-
我是所有这些平台的新手,所以请尽可能提供代码 sn-ps。
标签: javascript c# jquery html asp.net