我有一个带有文本框和2个按钮'保存'和'取消'的表单。
保存 - 将数据存储到数据库并清除所有字段。 取消 - 清除所有字段。 (我通过对同一页面执行server.transfer来清除所有字段。)
我希望标签在单击“保存”按钮并清除表单后显示“已添加课程”。
我查看过View State和Session Variables但是还没有找到解决我问题的具体方法。非常感谢任何帮助或建议。
下面是我的aspx和代码背后的代码。感谢。
Admin_Course_Add.aspx
<asp:Content ID="Content3" ContentPlaceHolderID="rightNavigation" runat="server">
<script type="text/javascript">
`/`/JS for validations
`enter code here` $(document).ready(function () {
$("#form1").validate({
rules: { '<%=tbCourseName.UniqueID %>': { required: true, maxlength: 25 },
'<%=tbShortName.UniqueID %>': { maxlength: 10 },
'<%=tbPointScale.UniqueID %>': { required: true, digits: true },
'<%=tbDescription.UniqueID %>': { maxlength: 50 }
},
messages: {}
});
$("#imgBtn_A_add").click(function (evt) {
// Validate the form and retain the result.
var isValid = $("#form1").valid();
// If the form didn't validate, prevent the
// form submission.
// If the form didn't validate, prevent the
// form submission.
if (!isValid)
evt.preventDefault();
});
$("#imgBtn_A_cancel").click(function () {
$("#form1").validate().cancelSubmit = true;
$("#form1").submit();
return false;
});
</script>
<div class="Admin_rightNavtop">
<table style="margin: 0 auto">
<tr>
<td>
<asp:TextBox ID="tbCourseName" runat="server" class="tbSize_large" />
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="tbShortName" runat="server" class="tbSize_large" />
</td>
</tr>
</table>
</div>
<center>
<div class="Admin_action">
<asp:ImageButton ID="imgBtn_A_add" ImageUrl="../Images/Add.png" runat="server" class="Admin_action_imgSize_small"
OnClick="add_Click" />
<asp:ImageButton ID="imgBtn_A_cancel" ImageUrl="../Images/Cancel.png" OnClick="cancel_Click"
runat="server" class="Admin_action_imgSize_small"/>
</div>
</center>
</asp:Content>
Admin_Course_Add.aspx.cs(代码背后)
protected void Page_Load(object sender,EventArgs e) { if(!Page.IsPostBack) { dbConnection dbConn = new dbConnection(); DataTable dt = new DataTable(); SqlConnection connection = new SqlConnection(“Data Source = VC-SQL2008; Integrated Security = True; database = CORP”);
dt = Admin_Course_WebService.PopulateCourseLevel();
ddlCourseLevel.DataSource = dt;
ddlCourseLevel.DataTextField = "Name";
ddlCourseLevel.DataValueField = "Id";
ddlCourseLevel.DataBind();
}
}
protected void add_Click(object sender, ImageClickEventArgs e)
{
DataTable dt = new DataTable();
string name = tbCourseName.Text;
string short_name = tbShortName.Text;
int id = Convert.ToInt32(ddlCourseLevel.SelectedItem.Value);
bool isDeleted = false;
Admin_Course_WebService.AddCourse(name, short_name, graded, point_scale, id, description, isDeleted);
Server.Transfer("Admin_Course_Add.aspx");
}
protected void cancel_Click(object sender, ImageClickEventArgs e)
{
Server.Transfer("Admin_Course_Add.aspx");
}
答案 0 :(得分:0)
首先为什么要通过ServerTransfer清除字段?
其次,你可以在QueryString中发送参数
例如:
Server.Transfer("Admin_Course_Add.aspx?ClearParams=Yes");
并在页面加载中添加
if(Request["ClearParams"].ToString() == "Yes")
{
Show My Lable
}