我有一個帶有文本框和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(代碼隱藏)
保護無效的Page_Load(對象發件人,EventArgs的){ 如果 (!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");
}
這是一個cookie的工作嗎?重定向需要視圖狀態,我不太在意會話變量。除此之外,你已經有cookie或querystrings ... – Tim 2012-03-23 18:59:50
查詢字符串確實聽起來像我需要看的東西。謝謝! – user1288906 2012-03-26 14:31:17