Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ObjectDataSource Causes Double PostBack

Status
Not open for further replies.

Meleagant

Programmer
Aug 31, 2001
166
US
All,

Don't know if this is by design or a bug of mine. I have an ObjectDataSource on a page that loads an asp:gridview. Actually it is a grid with a frozen header that I found on CodePlex, but for all purposed it is an asp:gridview.

Debugging the page and putting a break point in the SelectMethod I find that the break point is hit twice. My question is why/how? Has anyone else seen this? I'm not calling gvWorklist.DataBind anywhere in the code behind. I am letting the ODS take care of everything, and it seems that it is doing its job twice.

Has anyone seen this similar Double Post Back behaviour?

Here is the aspx page:
Code:
<asp:ObjectDataSource ID="odsWorklist" TypeName="GridViewHelper" SelectMethod="GetWorkListData"
 runat="server" EnableCaching="False" EnableViewState="false">
     <SelectParameters>
         <asp:QueryStringParameter Direction="input" Name="WorklistId" QueryStringField="worklist_id" Type="int16" />
         <asp:SessionParameter Direction="input" Name="EmpId" SessionField="empid" Size="10" Type="string" />
         <asp:SessionParameter Direction="input" Name="DataSource" SessionField="odbc_dsn" Size="10" Type="string" />
         <asp:ControlParameter ControlID="dateWorklist" Direction="input" Name="WorkListDate" PropertyName="text" Size="20" Type="string" />
         <asp:QueryStringParameter Direction="input" Name="ReportFilterKey" QueryStringField="orptfltr_key" Size="20" Type="String" />
         <asp:SessionParameter Direction="input" Name="UserId" SessionField="userid" Size="10" Type="string" />
         <asp:SessionParameter Direction="input" Name="ClientDSN" SessionField="clientdsn" Size="10" Type="string" />
         <asp:ControlParameter ControlID="ddlBillReady" Direction="input" Name="isBillReady" PropertyName="SelectedIndex" Type="Int16" />
     </SelectParameters>
</asp:ObjectDataSource>

<cc1:FrozenGridView ID="gvWorkList" runat="server" AutoGenerateColumns="false" AllowSorting="true" Enabled="true" GridLines="Both" EnableViewState="false" DataSourceID="odsWorklist" Scrolling="both" CssClass="tv"
LockColumn="0">
    <AlternatingRowStyle CssClass="tableViewAlternatingRow" />
    <HeaderStyle CssClass="tableViewHeader" />
    <RowStyle CssClass="tableViewRow" />
    <SelectedRowStyle CssClass="tableViewSelectedRow" />
    <Columns>
        <asp:TemplateField>
            <itemtemplate>
                <input type="checkbox" runat="server" id="cbChoice" onclick="chChoice_Click(this)" />
             </itemtemplate>
        </asp:TemplateField>
     </Columns>
     <PagerSettings Mode="Numeric" Position="TopAndBottom" />
     <PagerStyle CssClass="tableViewPager frozenTop" Wrap="true" />
</cc1:FrozenGridView>

* Sine scientia ars nihil est
* Respondeat superior
 
This is why I suggest you don't use the datasource controls. You can't debug them.
 
Just use a straight databind? Like this --

gridView.DataSource = functionReturnDataSet()
gridView.DataBind()



* Sine scientia ars nihil est
* Respondeat superior
 
Yes exactly, you can use Microsoft's Data Access Application Block for .NET v2 also, just a suggestion if you don't have something like that built.
 
+1 for the termination of datasource controls. They do nothing but promote bad design choices.

as for the problem... I have seen this happen while debugging because VS uses a virtual IIS engine "thing". (can't think of the name right now). anyway if you placed this in an intance of IIS and visited the site it shouldn't happen.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I think you are referring to the Cassinie?? engine which will use a virtual port on your PC. However, you can set up VS2005 to not use it and use IIS instead.
 
This is why I hate programming sometimes. You read in one place (probably somewhere on the MSDN) that using ObjectDataSource controls are this great tool that makes your life as a programmer easier. So I started using them...in ALL of my gridViews.

Then you find out from others that these things are abominations and should be touched with a 10ft pole.

I've got probably upwards of 50 of them scattered throughout my site. Now I feel that sinking feeling in my stomach at the thought of reworking all of those grids to databind differently.

It is a little consolation that this "Double Postback" should not be happening in production, I will try and confirm that with a simple logging statement before I start changing out my grids (and get a couple more gray hairs).

Thanks for your replies, I really appreciate the advice.

* Sine scientia ars nihil est
* Respondeat superior
 
I wouldn't go crazy chaning all of your pages just yet. For now, if I were you, I'd leave the datasource controls on any pages that are simple, let's say a report that just displays data. For anything else that gets more complex, updating, paging etc, I would rework those pages. Then once that is done, go back and change the other pages as well.
 
Double Post seems to occur in production as well. Put a logging statement in there and it wrote out "In GetWorklist Data" twice.

Crap on a stick! I never noticed before, or never thought it was a big deal until now.



* Sine scientia ars nihil est
* Respondeat superior
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top