Is it possible that when a user clicks "update" or "cancel" from the "edit.aspx" page that it takes them back to same record on the "list.aspx" page. This becomes an issue when there are a large number of records and the user has to click the "paging" button
on the GridView. It takes them back to the very first record by default.
I'm assuming you have Master/Details set up two pages, where the GridView control is on the list.aspx page and the details control FormView or DetailsView on the edit.aspx page.
There are a couple of ways I can think of. First, have the GridView and the Details control on the same page. If you do this, when the cancel or update button is clicked, the gridview will retain it's current row position. The other way is to send the record
ID back in the query string to the list.aspx page. Then write some code to select the correct row in the GridView.
Protected Sub DetailsView1_ItemInserted(ByVal sender As Object, _
ByVal e As DetailsViewInsertedEventArgs)
'If ((e.Exception Is Nothing) _
' OrElse e.ExceptionHandled) Then
' Response.Redirect(table.ListActionPath)
'End If
End Sub
Protected Sub DetailsDataSource_Inserted(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.LinqDataSourceStatusEventArgs) _
Handles DetailsDataSource.Inserted
If ((e.Exception Is Nothing) _
OrElse e.ExceptionHandled) Then
Response.Redirect(table.GetActionPath(PageAction.Details, e.Result))
End If
End Sub
And for the Edit page:
Protected Sub DetailsView1_ItemUpdated(ByVal sender As Object, _ ByVal e As DetailsViewUpdatedEventArgs)
'If ((e.Exception Is Nothing) _
' OrElse e.ExceptionHandled) Then
' Response.Redirect(table.ListActionPath)
'End If
End Sub
Protected Sub DetailsDataSource_Updated(ByVal sender As Object, _ ByVal e As System.Web.UI.WebControls.LinqDataSourceStatusEventArgs) _ Handles DetailsDataSource.Updated
If ((e.Exception Is Nothing) _
OrElse e.ExceptionHandled) Then
Response.Redirect(table.GetActionPath(PageAction.Details, e.Result))
End If
End Sub
[:D]
Dynamic DataReturn to Page after Edit or Insert
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
Protected Sub DetailsView1_ItemCommand(ByVal sender As Object, _
ByVal e As DetailsViewCommandEventArgs) _
Handles DetailsView1.ItemCommand
If (e.CommandName = DataControlCommands.CancelCommandName) Then
Dim path = Request.RawUrl.Replace("Edit", "Details")
Response.Redirect(path)
End If
End Sub
defyant_2004
Member
55 Points
337 Posts
Clicking Cancel Question
Feb 18, 2009 01:33 PM|LINK
Is it possible that when a user clicks "update" or "cancel" from the "edit.aspx" page that it takes them back to same record on the "list.aspx" page. This becomes an issue when there are a large number of records and the user has to click the "paging" button on the GridView. It takes them back to the very first record by default.
sjnaughton
All-Star
27320 Points
5459 Posts
MVP
Re: Clicking Cancel Question
Feb 18, 2009 01:52 PM|LINK
This will do it for Insert:
protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e) { //if (e.Exception == null || e.ExceptionHandled) //{ // Response.Redirect(table.ListActionPath); //} } protected void DetailsDataSource_Inserted(object sender, LinqDataSourceStatusEventArgs e) { if (e.Exception == null || e.ExceptionHandled) { Response.Redirect(table.GetActionPath(PageAction.Details, e.Result)); } }Note I commented out the OnInserted Event for the because you don't need it anymore.
And this for Edit. [:D]
Dynamic Data Return to Page after Edit or Insert
Always seeking an elegant solution.
KashifB
Member
503 Points
403 Posts
Re: Clicking Cancel Question
Feb 18, 2009 01:55 PM|LINK
I'm assuming you have Master/Details set up two pages, where the GridView control is on the list.aspx page and the details control FormView or DetailsView on the edit.aspx page.
There are a couple of ways I can think of. First, have the GridView and the Details control on the same page. If you do this, when the cancel or update button is clicked, the gridview will retain it's current row position. The other way is to send the record ID back in the query string to the list.aspx page. Then write some code to select the correct row in the GridView.
defyant_2004
Member
55 Points
337 Posts
Re: Clicking Cancel Question
Feb 18, 2009 06:21 PM|LINK
Would you happen to have the vb version of that code? and does it work for the "cancel" option as well?
sjnaughton
All-Star
27320 Points
5459 Posts
MVP
Re: Clicking Cancel Question
Feb 19, 2009 10:08 AM|LINK
I'll sort it in VB for you [:D]
Dynamic Data
Always seeking an elegant solution.
sjnaughton
All-Star
27320 Points
5459 Posts
MVP
Re: Clicking Cancel Question
Feb 19, 2009 10:20 AM|LINK
Here's the VB for the Insert page:
And for the Edit page: [:D]Dynamic Data Return to Page after Edit or Insert
Always seeking an elegant solution.
defyant_2004
Member
55 Points
337 Posts
Re: Clicking Cancel Question
Feb 19, 2009 01:08 PM|LINK
Thank you very much.
sjnaughton
All-Star
27320 Points
5459 Posts
MVP
Re: Clicking Cancel Question
Feb 19, 2009 01:47 PM|LINK
And Here's the cancel in VB:
And here's the c#:[:D]
Note: you don't need to create the variable path you can just:
Response.Redirect(Request.RawUrl.Replace("Edit", "Details"))
Dynamic Data Cancel or Insert Return to Page after Edit
Always seeking an elegant solution.