Hi
I'm trying to get an instance of UserLists to persist after it's been used
by the GridView. I understand from the documentation that The
OnObjectCreated event allows access to the instance. I have a TotalUsers
property which is initiated when the GetUsers method is called, however it
is empty after the OnObjectCreated event runs. What am I doing wrong? Is
there a way to get the Row count from the GetUsers method (It is a
DataTable)? I don't want to call the GetUsers method twice.
Thanks for your help.
Andrew
protected void Page_Load(object sender, EventArgs e)
{
ObjectDataSource1.TypeName = "Business.UserLists";
ObjectDataSource1.SelectMethod = "GetUsers";
}
protected void ObjectDataSource_Created(object sender,
ObjectDataSourceEventArgs e)
{
UserLists users = (UserLists)e.ObjectInstance;
Response.Write(users.TotalUsers.ToString());
} 9 11809
OK, I've found that I can use the ObjectDataSourceStatusEventArgs class in
the OnSelected method to get the row count of the DataTable. But why do all
these events get called twice? I only have one ObjectDataSource and
GridView.
protected void ObjectDataSource_Selected(object sender,
ObjectDataSourceStatusEventArgs e)
{
//ReturnValue is a DataTable
DataTable dt = (DataTable)e.ReturnValue;
Response.Write(dt.Rows.Count.ToString());
}
"J055" <j0**@newsgroups.nospam> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl... Hi
I'm trying to get an instance of UserLists to persist after it's been used by the GridView. I understand from the documentation that The OnObjectCreated event allows access to the instance. I have a TotalUsers property which is initiated when the GetUsers method is called, however it is empty after the OnObjectCreated event runs. What am I doing wrong? Is there a way to get the Row count from the GetUsers method (It is a DataTable)? I don't want to call the GetUsers method twice.
Thanks for your help. Andrew
protected void Page_Load(object sender, EventArgs e) { ObjectDataSource1.TypeName = "Business.UserLists"; ObjectDataSource1.SelectMethod = "GetUsers"; }
protected void ObjectDataSource_Created(object sender, ObjectDataSourceEventArgs e) { UserLists users = (UserLists)e.ObjectInstance; Response.Write(users.TotalUsers.ToString()); }
Hi J055,
Thank you for posting.
Yes, the Selected event will always be fired after the
objectdatasource(also available to other datasource controls) and we can
access some returned value or returned parameters there. As for the event
firing twice, it is not the expected behavior. Have you tried also register
the GridView's "Databinding" event to see whether it is also called twice.
BTW, if convenient, would you provide some detailed code logic on the page
and your data access object class (used in objectdatasource control)?
Regards,
Steven Cheng
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Hi Steven
I've finally been able to work out what's causing events to be fired twice.
I registered the Databinding event as you suggested. The Databinding fires
twice when I add this line to the Page_Load event.
GridView1.BottomPagerRow.CssClass = "break";
//It only seems to do it on Postbacks. The declarative code looks like this:
<asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1"
OnDataBinding="Grid_DataBinding"
AllowSorting="True" AutoGenerateColumns="False" CssClass="data"
AllowPaging="true"
EnableTheming="False" EnableViewState="False" GridLines="None" PageSize="5"
PagerSettings-Mode="NumericFirstLast"
PagerSettings-Position="TopAndBottom">
<Columns>
<asp:ImageField>
</asp:ImageField>
<asp:BoundField DataField="FullName" HeaderText="Name"
SortExpression="LastName" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email"
/>
<asp:BoundField DataField="LastLogin" HeaderText="Last Login"
HtmlEncode="False"
SortExpression="LastLogin" />
<asp:BoundField DataField="AccessLevel" HeaderText="Access Level"
SortExpression="AccessLevel" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetUsers"
TypeName="Empetus.Accounts.Business.UserLists"></asp:ObjectDataSource>
Is this supposed to happen? I couldn't see why but you may be able to
provide me with an explanation. I can supply you with the whole project if
that helps.
Many thanks
Andrew
"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:QL**************@TK2MSFTNGXA01.phx.gbl... Hi J055,
Thank you for posting.
Yes, the Selected event will always be fired after the objectdatasource(also available to other datasource controls) and we can access some returned value or returned parameters there. As for the event firing twice, it is not the expected behavior. Have you tried also register the GridView's "Databinding" event to see whether it is also called twice. BTW, if convenient, would you provide some detailed code logic on the page and your data access object class (used in objectdatasource control)?
Regards,
Steven Cheng Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Hi Andrew,
Thanks for the response.
Of course, this is an unexpected behavior. However, I've ever encountered
some problem on certain events on page get fired twice, some of them are
caused by the page be posted back(or requested) twice. For example, when
there is an image tag that put a relative path reference the page's url, it
makes a GET http request to the page, thus make the page's load event
execute twice. Not sure whether this could be the case and related to your
page's code logic. I think you can try looking up the IIS log of the server
to see whether there will always occur double request entires when that
problem page get postback, if so, it is suffering the similiar problem.
Regards,
Steven Cheng
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Hi Steven
I've been using the ASP.NET development server so haven't had change to look
in the IIS logs but I have since moved the line to the Page PreRender event
which has stopped the DataBinding event firing twice...
protected void Page_PreRender(object sender, EventArgs e)
{
if (UserGrid.AllowPaging)
UserGrid.BottomPagerRow.CssClass = "break";
}
Thinking about it, this may be a more appropriate place for setting these
types of properties?
Cheers
Andrew
"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:cg**************@TK2MSFTNGXA01.phx.gbl... Hi Andrew,
Thanks for the response.
Of course, this is an unexpected behavior. However, I've ever encountered some problem on certain events on page get fired twice, some of them are caused by the page be posted back(or requested) twice. For example, when there is an image tag that put a relative path reference the page's url, it makes a GET http request to the page, thus make the page's load event execute twice. Not sure whether this could be the case and related to your page's code logic. I think you can try looking up the IIS log of the server to see whether there will always occur double request entires when that problem page get postback, if so, it is suffering the similiar problem.
Regards,
Steven Cheng Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights. Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.)
Thanks for your response Andrew,
Yes, Prerender is a good place for applying styles or other UI setting of
webserver control. However, I still feel very strange on the double
databinding behavior. Anyway, you can still have a check when hosting it in
IIS.
Regards,
Steven Cheng
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Hi Steven
I've checked this in IIS. Still get the same problem as with the development
web server.
To test I did the following:
1. Load the page - DataBinding fires once
2. Click a GridView page button - DataBinding fires twice (and for any
further postbacks)
The page didn't contain any links to external files (images, css etc). This
is the IIS log file entries for the above:
#Software: Microsoft Internet Information Services 5.1
#Version: 1.0
#Date: 2006-04-06 16:26:26
#Fields: date time c-ip cs-method cs-uri-stem sc-status
2006-04-06 16:26:26 127.0.0.1 GET /Default.aspx 200
2006-04-06 16:26:28 127.0.0.1 POST /Default.aspx 200
If I move [ GridView1.BottomPagerRow.CssClass = "break"; ] to the
Page_PreRender event from the Page_Load event it doesn't fire twice when the
page buttons are clicked and I get exactly the same IIS log output.
I've also just noticed that if I put a ButtonField with an image in the
GridView the DataBinding event fires twice on postback. e.g.
<asp:ButtonField ButtonType="Image" ImageUrl="~/images/edit.gif" Text="Edit"
/>
I can't figure out what's happening here so would really appreciate some
suggestions on what's happening and how to resolve it.
Thanks again
Andrew
Hi Steven
I posted the response above on the 6th. I wondered if
you'd had chance to look at it and come up with any answers? I'm finding
that my pages using the GridView and ObjectDataSource controls seem to be
calling my Business Object method twice for no apparent reason. I clearly
can't release anything into production with this type of behaviour so I'd be
very grateful if you could let me know how to resolve this.
Cheers
Andrew
Thanks for the response Andrew,
This is indeed a strange behavior, so far I haven't found any known issue
on this. Based on my experience, this issue may require further
troubleshooting. And if you feel it urgent, you may consider contact CSS to
perform thorough troubleshooting/debugging on it. Also, you need to create
a simplified reproduce project/page on this.
Regards,
Steven Cheng
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kjetil Klaussen |
last post by:
Hi,
I’m having some troubles trying to bind my dataset to a GridView control
through an ObjectDataSource control. The binding works fine for regular
columns in my dataset, but I can’t seem...
|
by: David Hubbard |
last post by:
I am using a GridView to display a set of objects that have a parent-child
relationship. Each object, MyBO, has
an ID property that is used to get the children of that object.
class MyBO
{
...
|
by: jeffmagill |
last post by:
Hi Everybody,
I'm really hoping that someone can help me out because I have spent too
much time on this project already!
Basically, I have a DetailsView that handles all the Edits for a...
|
by: syl |
last post by:
Hello
I am trying to create a "easy to use" gridview with filters (dropdownlist in
headers), sorting...and much more....
In order to do that, i prefer to use a objectdatasource (ODS) beacause...
|
by: =?Utf-8?B?QWRhciBXZXNsZXk=?= |
last post by:
Hi All,
I have a GridView inside the EditItemTemplate of a FormView. Both FormView
and GridView are data bound using an ObjectDataSource. When the FormView's
ObjectDataSource object has a...
|
by: newbieAl |
last post by:
I have a stored procedure in mysql and I am calling it via a method and objectdatasource. I have two select methods. One that gets a list of employees and the other that gets one specific employee by...
|
by: newbieAl |
last post by:
I have a stored procedure in mysql and I am calling it via a method and objectdatasource. I have two select methods. One that gets a list of employees and the other that gets one specific employee by...
|
by: Rote Rote |
last post by:
Hi Guys, I have a simple Edit,Update Gridview and i'm using
ObjectDatasource with dataset generated and TableAdapters I can do an
update no problem.
But can't get my delete to work. When i look at...
|
by: =?Utf-8?B?SnVsaWEgQg==?= |
last post by:
Hi all, this is a second post, so apologies, but I never had an answer to my
first post (several weeks ago) and I really need some help.
I'm using a .Net 2.0 Gridview which is populated using an...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |