Reputation: 1177
If a user is making an edit and clicks cancel, how can i return them to the page before the edit was made? Not jus refering them back to the previous page, but referring them back to how it was before they decided to edit.
If i need to me more thorough please ask.
I used this code but it just refers back to the previous page. I had a previous thread about a problem but couldnt find the solution.
When a user clicks add new row button it opens up the new row in a edit and cancel form. If the user clicks cancel it automatically adds the row as blank, I dont want that I want the row to be deleted. I was thinking if I could set it to return to its orginal form before the new row was created oit would work the same way.
protected void gv_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Insert") //- this is needed to explain that the INSERT command will only work when INSERT is clicked
{
dbcon.Execute("INSERT INTO PROJ_ASP (TRANS_CD) VALUES('')", "ProjectASPConnectionString");
gv.DataBind();
gv.EditIndex = gv.Rows.Count - 1;
gv.DataBind();
}
}
protected void gv_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
///When cancel is clicked, redirect page to orginal page
Response.Redirect("Default.aspx");
I actually think I understand what my issue is, the way I setup it up is anytime the user clicks INSERT it automatically adds a blank row into the database REGARDLESS if its empty. What can i do to not allow it to insert it into the database until all rows are complete? Im assuming its a code i would be placing under gv_RowCommand
Upvotes: 0
Views: 273
Reputation: 26406
I don't know if this will work in asp.net but I do it in PHP. Post back to the previous page.
Try this, no guarantee
<asp:Button ID="CancelButton" Text="Cancel" PostbackUrl="PreviousPage.aspx" />
and see if you can repopulate your form with the posted values.
The easiest solution I have ever come across with asp.net is using the <asp:MultiView />
or something like that
Upvotes: 0
Reputation: 31206
you can use the ASP.NET ViewState Property to keep track of your state
Upvotes: 1