Monday, August 16, 2010

In ASP.net the GirdView Control causes my page to submit twice with one click on any row command button, Why?

In ASP.net the GirdView Control causes my page to submit twice with one click on any row command button, Why? and how can i fix it





i'm using a Grid View with a Bound Command field





%26amp; i have a code that handles the RowCommand event of the GridView





the problem is during testing the code works fine, but sometims ';NOT ALWAYS'; all of the page events get excuted twice including the RowCommand event, in other words it is same as if the exact page was submitted twice





this all happens when i click on the command field of the GridView ';SOME TIMES';





dont tell me to use the Page.isPostBack because the page i'm constructing wroks as a post back page .. not to mention that the exact page is submitted twice for one actual submit





if there is anyone with a clue, i would appreciate it !!In ASP.net the GirdView Control causes my page to submit twice with one click on any row command button, Why?
Please post your markup for the GridView and the code for your Page_Load and GridView's RowCommand event handler.





I've seen similar things in the past, but it's almost impossible to diagnose the problem without code.








---





Although I don't like the GridView's framework for commands, I think it is superior to the original DataGrid. Here's what I usually do:





(inside the %26lt;Columns%26gt; of the GridView)


%26lt;asp:TemplateField%26gt;


%26lt;ItemTemplate%26gt;


%26lt;asp:ImageButton runat=';server'; ImageUrl=';~/images/delete.gif'; CommandArgument='%26lt;%# Eval(';Identifier';) %%26gt;' OnCommand =';DeleteEmployee_Command'; /%26gt;


%26lt;/ItemTemplate%26gt;


%26lt;/asp:TemplateField%26gt;





(in the codebehind)





protected void DeleteEmployee_Command (Object sender, CommandEventArgs e)


{


// e.CommandArgument holds the identifier (primary key) of the record i want to delete


}In ASP.net the GirdView Control causes my page to submit twice with one click on any row command button, Why?
You do not need to specify the OnRowCommand if you have the autoEventWireUp = true.

No comments:

Post a Comment