Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello everyone.

Scenario:
I have a simple GridView with an ItemTemplateField which has a Checkbox in it. Such Checkbox is wired to fire the onCheckedChanged event, which for some reason I ignore, only fires when checking, but not unchecking. In turn, every onCheckedChanged event of such nature get cued some how, somewhere, and fire in sequence after another control triggers its on server side event.

Anyhow, that's not the question. Here's the grid, and as you can see, the checkbos is not bound to any data source:

<asp:GridView ID="Grid" runat="server" AutoGenerateColumns="False"  >
         <Columns>
             <asp:TemplateField Visible="false">
                 <ItemTemplate><asp:Label id="lbCesionID" runat ="server" Text='<%# Eval("idCesion") %>' /></ItemTemplate>
             </asp:TemplateField>
             <asp:TemplateField>
                 <ItemTemplate><asp:CheckBox runat="server" ID="chkSelected" AutoPostBack="true" OnCheckedChanged="GridCheckedChanged" Checked="false" /></ItemTemplate>
             </asp:TemplateField>
             <asp:BoundField DataField="DBSourceField" HeaderText="ThisHeader" ></asp:BoundField>
         </Columns>
     </asp:GridView>



Looking a the html code, I found this attached to my checkboxes:

onclick="javascript:setTimeout('__doPostBack(\'ctl00$MainContent$ucCesionesDocs$Grid$ctl02$chkSelected\',\'\')', 0)"


And since I have no clue how it got there, I am most certainly blaming it for my hurdle.

Does anybody know where does such thing comes from? Where could I possible be adding it without knowing. If so, how can I get rid of it?

Thank you for your help.

What I have tried:

Intercepting the OnRowDataBound event, locating the checkbox within the grid's row, and removing the "onclick" attribute, but that javascript call remains in place.

I found a setTimeout function defined in JQuery, but, again, I am not adding such thing (at least on purpose).
Posted
Updated 29-Jun-17 5:50am

1 solution

It comes from the fact that you've set AutoPostBack=true. This means the form will submit when the field changes and that can only be done via javascript so the asp.net framework facilitates this by adding the appropriate js to your page.
 
Share this answer
 
Comments
alexvw 29-Jun-17 12:46pm    
Thanks a lot for the clarification; I do not recall ever seeing it before. Now, it is time to find the true reason for my real problem.

Cheers!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900