Clicking Cancel Questionhttp://forums.asp.net/t/1386578.aspx/1?Clicking+Cancel+QuestionThu, 19 Feb 2009 13:47:23 -050013865782949597http://forums.asp.net/p/1386578/2949597.aspx/1?Clicking+Cancel+QuestionClicking Cancel Question <p>Is it possible that when a user clicks &quot;update&quot; or &quot;cancel&quot; from the &quot;edit.aspx&quot; page that it takes them back to same record on the &quot;list.aspx&quot; page.&nbsp; This becomes an issue when there are a large number of records and the user has to click the &quot;paging&quot; button on the GridView.&nbsp; It takes them back to the very first record by default.</p> 2009-02-18T13:33:18-05:002949637http://forums.asp.net/p/1386578/2949637.aspx/1?Re+Clicking+Cancel+QuestionRe: Clicking Cancel Question <p>This will do it for Insert:&nbsp; <pre class="prettyprint">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)); } }</pre> <P>Note I commented out the OnInserted Event for the&nbsp;because you don't need it anymore.&nbsp; <pre class="prettyprint"><SPAN class=kwd>protected void</SPAN> DetailsView1_ItemUpdated(<SPAN class=kwd>object</SPAN> sender, DetailsViewUpdatedEventArgs e) { <SPAN class=cmt>//if (e.Exception == null || e.ExceptionHandled) //{ // Response.Redirect(table.ListActionPath); //}</SPAN> } <SPAN class=kwd>protected void</SPAN> DetailsDataSource_Updated(<SPAN class=kwd>object</SPAN> sender, LinqDataSourceStatusEventArgs e) { <SPAN class=kwd>if</SPAN> (e.Exception == <SPAN class=kwd>null</SPAN> || e.ExceptionHandled) { Response.Redirect(table.GetActionPath(PageAction.Details, e.Result)); } } </pre> </p> <p>And this for Edit. [:D]</p> 2009-02-18T13:52:45-05:002949643http://forums.asp.net/p/1386578/2949643.aspx/1?Re+Clicking+Cancel+QuestionRe: Clicking Cancel Question <p>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.</p> <p>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&nbsp;the&nbsp;query string to the list.aspx page. Then write some code to select the correct row in the GridView.</p> 2009-02-18T13:55:28-05:002950194http://forums.asp.net/p/1386578/2950194.aspx/1?Re+Clicking+Cancel+QuestionRe: Clicking Cancel Question <p>Would you happen to have the vb version of that code?&nbsp; and does it work for the&nbsp;&quot;cancel&quot; option as well?</p> 2009-02-18T18:21:46-05:002951862http://forums.asp.net/p/1386578/2951862.aspx/1?Re+Clicking+Cancel+QuestionRe: Clicking Cancel Question <p>I'll sort it in VB for you [:D]</p> 2009-02-19T10:08:35-05:002951884http://forums.asp.net/p/1386578/2951884.aspx/1?Re+Clicking+Cancel+QuestionRe: Clicking Cancel Question <p>Here's the VB&nbsp;for the Insert page:<pre class="prettyprint">Protected Sub DetailsView1_ItemInserted(ByVal sender As Object, _<br> 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, _<br> ByVal e As System.Web.UI.WebControls.LinqDataSourceStatusEventArgs) _<br> Handles DetailsDataSource.Inserted If ((e.Exception Is Nothing) _ OrElse e.ExceptionHandled) Then Response.Redirect(table.GetActionPath(PageAction.Details, e.Result)) End If End Sub</pre>And for the Edit page:&nbsp;<pre class="prettyprint"><SPAN class=kwd>Protected Sub</SPAN> DetailsView1_ItemUpdated(<SPAN class=kwd>ByVal</SPAN> sender <SPAN class=kwd>As Object</SPAN>, _<BR> <SPAN class=kwd>ByVal</SPAN> e <SPAN class=kwd>As</SPAN> DetailsViewUpdatedEventArgs) <SPAN class=cmt>'If ((e.Exception Is Nothing) _ ' OrElse e.ExceptionHandled) Then ' Response.Redirect(table.ListActionPath) 'End If </SPAN><SPAN class=kwd>End Sub Protected Sub</SPAN> DetailsDataSource_Updated(<SPAN class=kwd>ByVal</SPAN> sender <SPAN class=kwd>As Object</SPAN>, _<BR> <SPAN class=kwd>ByVal</SPAN> e <SPAN class=kwd>As</SPAN> System.Web.UI.WebControls.LinqDataSourceStatusEventArgs) _<BR> <SPAN class=kwd>Handles</SPAN> DetailsDataSource.Updated <SPAN class=kwd>If</SPAN> ((e.Exception <SPAN class=kwd>Is Nothing</SPAN>) _ <SPAN class=kwd>OrElse</SPAN> e.ExceptionHandled) <SPAN class=kwd>Then</SPAN> Response.Redirect(table.GetActionPath(PageAction.Details, e.Result)) <SPAN class=kwd>End If End Sub</SPAN></pre>[:D]</p> 2009-02-19T10:20:32-05:002952261http://forums.asp.net/p/1386578/2952261.aspx/1?Re+Clicking+Cancel+QuestionRe: Clicking Cancel Question <p>Thank you very much.</p> 2009-02-19T13:08:34-05:002952355http://forums.asp.net/p/1386578/2952355.aspx/1?Re+Clicking+Cancel+QuestionRe: Clicking Cancel Question <p>And Here's the cancel in VB:&nbsp;<pre class="prettyprint">Protected Sub DetailsView1_ItemCommand(ByVal sender As Object, _<br> ByVal e As DetailsViewCommandEventArgs) _<br> Handles DetailsView1.ItemCommand If (e.CommandName = DataControlCommands.CancelCommandName) Then Dim path = Request.RawUrl.Replace(&quot;Edit&quot;, &quot;Details&quot;) Response.Redirect(path) End If End Sub</pre>And here's the c#:&nbsp;<pre class="prettyprint"><SPAN class=kwd>protected void</SPAN> DetailsView1_ItemCommand(<SPAN class=kwd>object</SPAN> sender, DetailsViewCommandEventArgs e) { <SPAN class=kwd>if</SPAN> (e.CommandName == DataControlCommands.CancelCommandName) { var path = Request.RawUrl.Replace(<SPAN class=st>"Edit"</SPAN>, <SPAN class=st>"Details"</SPAN>); Response.Redirect(path); <SPAN class=cmt>//Response.Redirect(table.ListActionPath);</SPAN> } }</pre> </p> <p>[:D]</p> <p>Note: you don't need to create the variable path you can just:</p> <p>Response.Redirect(Request.RawUrl.Replace(<span class="st">&quot;Edit&quot;</span>, <span class="st"> &quot;Details&quot;</span>))<br> </p> 2009-02-19T13:47:23-05:00