Delete command in GridView with response.redirect in a try catch

 Hi,

 I have these code:

 

protected void gvFaxLijst_RowCommand(object sender, GridViewCommandEventArgs e)
{
try{
if (e.CommandName == "Delete")
{
//code
Response.write("index.aspx",false);
}

}
catch(exception ex){
insertlog(...);
Server.Transfer("error.aspx");
}

The problem is that the Delete command isn't finished so I got an error (System.Web.HttpException)

When i remove the False in Response.write("index.aspx") then I got these error:

 [System.Threading.ThreadAbortException] = {Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}

 This is because a Response.redirect throws a "ThreadAbortException".

 
Someone with a solution?


 

 

 

0
DoaX
1/3/2008 2:10:59 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

9 Replies
646 Views

Similar Articles

[PageSpeed] 54

I'm not exactly sure what you are trying to accomplish, but if you are simply wanting to navigate to your "index.aspx" page AFTER the delete has ocurred, then simply place your code into the GridView.RowDeleted event instead. 

protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
	if (e.Exception == null)
		Response.Redirect("index.aspx");
}

Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
1/3/2008 3:03:39 PM
He doesn't fire RowDeleted after the Delete command in Rowcommand ...
0
DoaX
1/3/2008 3:21:59 PM

Did you set-up your handler within the GridView control? 

<asp:gridview id="GridView1" runat="server" onrowdeleted="GridView1_RowDeleted">
</asp:gridview>

Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
1/3/2008 3:33:36 PM
Yes, OnRowDeleted="gvFaxLijst_RowDeleted"
0
DoaX
1/3/2008 3:43:07 PM

Are you data-binding your GridView manually by chance? If so, I believe this may be some type of bug that I've experienced before. If you were using a DataSourceControl such as a SqlDataSource or ObjectDataSource, then I'd bet this event would fire. If you can't use this event, then you may just have to use the GridView.RowCommand handler somehow.


Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
1/3/2008 3:56:33 PM

 Are you data-binding your GridView manually by chance? Yes, i do

 if you were using a DataSourceControl such as a SqlDataSource or ObjectDataSource I dont' use sqldatasource or objectdatasource.

 GridView.RowCommand handler somehow. OK, but how? :)

0
DoaX
1/4/2008 7:26:29 AM

 Try this on GridView1_RowDeleting

    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        //Codes for Deletion here

        if (e.Exception == null)
        {
         Response.Redirect("index.aspx");
        }
      
        GridView1.EditIndex = -1;
        BindGrid();// Always bind your grid to reflect changes
       
    }

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDeleting="GridView1_RowDeleting" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"></asp:GridView> 


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
1/4/2008 7:48:47 AM

vinz,

at GridView1_RowDeleting it is not possible to do "e.Exception" 

0
DoaX
1/4/2008 8:29:02 AM

Hi DoaX ,

DoaX:
at GridView1_RowDeleting it is not possible to do "e.Exception"

 

Move code into GridView1_RowDeleted event , you can use e.Exception in that event.

 

 

 

 



Samu Zhang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
Samu
1/7/2008 6:52:24 AM
Reply:

Similar Artilces:

try catch finally / response.redirect / response.end flow control question
Hi Guys, Can any one tell me if the finally block would be executed in the following example (assuming that dbReader.read() returned false because no records were found).   Many Thanks! DanielTry dbCon = New SqlConnection(myconnectionstring) dbCon.Open() dbCom = dbCon.CreateCommand() strSQL + "SELECT * FROM bookings WHERE ID &gt; 9000" dbCom.CommandText = strSQL dbReader = dbCom.ExecuteReader() If dbReader.Read() Then 'init fields Else Response.Redirect("main.aspx") End if Finally dbReader.clo...

GridView-Mysql-bind Gridview control to SqlDataSource -problem-Delete Command
 DeleteCommand="DELETE FROM relatorios WHERE codigo=codigo"> this works but delete everythingi have tryed thisWHERE codigo='codigo' ">and WHERE codigo=?codigo"> sintax error on mysql the full code is below :  <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" CellPadding="4" DataKeyNames="codigo"  AutoGenerateDeleteButton="True"  DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="Non...

Try..Catch and Response.Redirect
I have sub that connect to a db to verify users. If the user is cleared the they are redirected to the next page and if not then they are forced to login again. I have noticed that during debug on my Try..Catch..Finally block an error is always fired on the resposne.redirect. Dim rs As SqlDataReader = objCMD.ExecuteReader If rs.Read() = False Then Response.Redirect("issuenewrga.aspx?OrderNum=" & txtOrderNum.Text & "&ItemNum=" & txtItemNum.Text & "&LineNum=" & txtLineNum.Text) ...

Delete command is Gridview control
Hi I have added delete command in gridview and want to delete record on click of delete command. I want vb code(code behind) not HTML, is it possible,  i am using ASP.Net 3.5.  Please post code which you use for delete command.so it's more clear your question.:)here i post Gridview RowDelete command event which fired when Gridview row deleted. These articals may helps you http://msdn.microsoft.com/en-us/library/ms972940.aspx, http://www.codeproject.com/KB/aspnet/InsertingWithGridView.aspx             &nbs...

try, catch, Response.Redirect problem
Hi,This is the code which makes me a problem: try{ Response.Redirect("SomePage.aspx");}catch{ ...someOperation():} It always goes to catch region...  i think you don't have that page in your web server. check it first.Got what you needed. Please mark as answer. This is a known issue, try to use the below code try {Response.Redirect("WebForm2.aspx",false);     }catch(Exception ex) { Response.Write(ex.Message); } HCHaissam Abdul MalakMCAD.NET| Blog | Sathesh_pandian:i think you don't have that page in your we...

Try catch, Response.Redirect, and endResponse
 Hi,I get an error email from this aspx page once a while. I have pasted the code skeleton below. The error email says the error occured at the line marked *, where sproc1 is being called. When I look up the database table, I see the sproc2 has been executed as well. I created a test page and changing the endResponse parameter to true or false did not make any difference, when an exception occurs the execution always jumps straight to the catch block. I wish the same thing was happening in the production page as well, but the sproc2 is always being called.try{    .....&nb...

response.redirect inside a Try Catch...
I’ve come across a situation where I have a response.redirect inside a TRY Catch The redirect seams to trigger an exception.   I found a work around but I’m scared it might cause other problems.   Response.redirect(“blah blah”, False)    ß the false seams to help … although I’m not 100% sure why …   You guys see any problem in this solution?   It should be ok. The second argument means whether the execution of the current page should be stopped or not. When you specified false, it means if should not stop and thus no error otherwise previosly it...

Response.Redirect and Try Catch Finally
If I have a Try Catch Finally block with a Response.Redirect in the Catch and a Connection.Close in the Finally, will the code in the Finally still execute before the Redirect takes place? Someone asked a similar question at this web site: http://www.error-bank.com/microsoft.public.dotnet.languages.vb.1/190535_Thread.aspxDarrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you! Thanks for the link. Can anyone confirm that, yes, the Finally will execute? Yes,it will execute....

Response.Redirect within Try Catch
Hi, I am using asp.net 2.0 and I have a page where I need to use the Try-Catch-Finally structure. Within the Try statement I have various commands and then at the end of it I have a Response.Redirect("....") to take the user to another page. Within my catch statement I also have a Response.Redirect("../errorPage.htm") which will take you to the error page if any exceptions occur. However, I have tested the page and I know there are no exceptions happening but the user is still getting redirected to the error page.  Is there anyway to make this not happen? I am using Smart Navigatio...

Trying to use the FAQ " Sorting and paging in the GridView control when not using data source controls "Sorting and paging in the GridView control when not using..."
and I am not getting the results I had hoped for.  I keep getting a "Compiler Error Message: CS0123: No overload for 'AdhocJobGridView_PageIndexChanged' matches delegate 'System.EventHandler'".   Here is my event handling... protected void AdhocJobGridView_PageIndexChanged(object sender, GridViewPageEventArgs e){ try { AdhocJobGridView.DataSource = wsBaseInfoArray; AdhocJobGridView.PageIndex = e.NewPageIndex; AdhocJobGridView.DataBind(); }catch (Exception ex) {throw ex; }   Here is my aspx... <asp:GridView ID="AdhocJobGridView...

Response.redirect without exception in a try catch?
I have these code: try{ if(!fuFaxnummer.PostedFile.FileName.EndsWith(".csv")){ Response.Redirect("faxnummerimport.aspx?ID=" + id + "&msg=2"); } //code to execute when the file is a .csv } catch (exception ex){ LogDA.insertLog(...); Response.Redirect("error.aspx"); }I know that "Response.Redirect" gives an Exception. When I set the bool endResponse at false (Response.redirect("",false)) there is no exception BUT he execute the code behind my IF(). Someone with a solution?      ...

Response.Redirect inside a Try Catch block
Can you put a Response.Redirect inside a Try Catch block?I think you will get a thread Abored Error, true? Who said so? I just tried it and it worked fine!!!!What is mainly the problem you are facing?RegardsBilal Hadiar, MCP, MCTS, MCPD, MCTMicrosoft MVP - Telerik MVP...

problem with Try and Catch "Response.Redirect ....."
If the try is succesfull it will also go to "2.aspx", any idea what is wrong with it? I tried remove the line of redirection to page 2.aspx. It works...if no error, it will go to 1.aspx. But when I include the Catch line. It will direct it to 2.aspx, eventhough there is no error... Try ------ ------ ------ Response.redirect("1.aspx") Catch Response.redirect("2.aspx") End Try Can you supply the try-catch code ?"I would love to change the world, but they won't give me the source code." -unknown Try SmtpMail.Send(msg) msg...

Response.Redirect not displaying the desired data from the database in a GridView control
I am doing a project on Online Flight Reservation System.When the Home Page of my site is displayed, the user will select his departure station,date of departure,cabin-type etc, depending upon the type of trip he is making, i.e., whether One-Way or RoundTrip.Now on selecting the One-Way trip, the controls for return date(txtDateTo) and return cabin-type should get disabled.And after clicking on the button for flight-schedule search, the user will get redirected to next page which will show the schedules of selected flights in a GridView Control, which is not happening. Here is the code of H...

Web resources about - Delete command in GridView with response.redirect in a try catch - asp.net.presentation-controls

GridView SelectedItem Binding Gotcha in WinRT
Last night when I was doing some WinRT hacking I was trying to setup databinding to the selected item in the GridView control and I ran into ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Advanced Search Gridview Latest News Releases All ...

CNW Group
... Services Beyond the Wire About CNW my CNW CNW Access CNW Directories Financials Webcasts Events my CNW All News Releases Advanced Search Gridview ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Add a Filter Gridview Latest News Releases All Today ...

New CmdLets of Powershell 2.0
New CmdLets of Powershell 2.0

Price Drop: Softbox
... objects- create product reflection- changing the background with something more interestingUse it as:- softbox- honeycomb softbox- gridview ...

Profile.aspx: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 25 Oct 2012

DotNetKicks.com - Upcoming stories
DotNetKicks.com is a community based news site edited by our members. It specialises in .NET development techniques, technologies and tools including ...

View Features - ExtendASP
Call 847-681-9827 or Request a Demo View Features Testimonials Pricing About Us Coming Soon ExtendASP exposes every feature, more than any other ...

Resources last updated: 1/4/2016 2:27:12 PM