ObjectDatasource - preventing DataBinding before I press Button

  • Thread starter Thread starter 3P
  • Start date Start date
3

3P

I would like to create a very simple form.

When client enters it he has a filter to set. Then push the button get the
data and display in GridView.
Grid uses ObjectDataSource and allows paging and sorting (using custom
stored proc returning only data needed on current page).
But seems that ObjectDataSource is refreshing data on every postback. It's
not ok because dropdowns in
filter also postback thus I hit the database and display data before
filter is set and before client
pushes the button. Plus it hits the database on first PageLoad.

Is there any way to prevent such a behaviour of ObjectDataSource? Or is
there a way to do it w/o ObjectDatasource?
Other then inheriting from GridView and overriding InitializePager (or sth
like that). I cannot find a way to tell
the grid how many records there is so it can generate the Pager.

I thought I found the solution by handling the Selecting event and
canceling it until user pushes the button. But when
there is data in grid and I cancel Selecting event the data in grid is
cleared :/

If it is not possible with ObjectDataSource, then I really don't know what
this control is for. Then it's totally unusable
for other then maybe one or two simplest solutions.


3P
 
3P said:
I would like to create a very simple form.

When client enters it he has a filter to set. Then push the button get
the data and display in GridView.
Grid uses ObjectDataSource and allows paging and sorting (using custom
stored proc returning only data needed on current page).
But seems that ObjectDataSource is refreshing data on every postback.
It's not ok because dropdowns in
filter also postback thus I hit the database and display data before
filter is set and before client
pushes the button. Plus it hits the database on first PageLoad.

Is there any way to prevent such a behaviour of ObjectDataSource? Or is
there a way to do it w/o ObjectDatasource?
Other then inheriting from GridView and overriding InitializePager (or
sth like that). I cannot find a way to tell
the grid how many records there is so it can generate the Pager.

I thought I found the solution by handling the Selecting event and
canceling it until user pushes the button. But when
there is data in grid and I cancel Selecting event the data in grid is
cleared :/

If it is not possible with ObjectDataSource, then I really don't know
what this control is for. Then it's totally unusable
for other then maybe one or two simplest solutions.

What are you talking about here? You don't want to go back to the database?
 
Dnia 18-03-2010 o 23:09:51 Mr. Arnold said:
What are you talking about here? You don't want to go back to the
database?

Only when client pushes GetMeData button. Not on every postback.
 
3P said:
Only when client pushes GetMeData button. Not on every postback.

Well, you need to change the binding source to do the binding in the
codebhind file on page_load it seems for the code.

If (!IsPostBack)
(
go get the data and bind it to the control, using a binding method
-- a first time load only -- if it's postback, then you don't do it.
}

This is not the control you're using a binding method of using a dataset
to bind to the control. But the principle is the same for any control
you're trying to bind the results of the SQL query to the control.

You have two choices of using a dataset to bind to the control or using
a collection to bind to a control by using a SQL datareader and
populating the collection of objects to bind to the collection to the
control.

http://demos.telerik.com/aspnet-ajax/treeview/examples/programming/databinding/defaultcs.aspx

You look at the example code for C# or VB and see how to do the binding
programmically. It may be easiest to use the dataset example.

Then in the button_click_event, you go read the data and bind it to the
control.

You have the control.
 
Dnia 19-03-2010 o 01:51:23 Mr. Arnold said:
Well, you need to change the binding source to do the binding in the
codebhind file on page_load it seems for the code.

If (!IsPostBack)
(
go get the data and bind it to the control, using a binding method
-- a first time load only -- if it's postback, then you don't do it.
}
Yeah this code works when I want to do it on button click. LOL.

I feel that You think that I don't anything about programming. But still
give me responses that have nothing to do with my problem.

That IsPostback is good for binding at the PageLoad not the button click.

And the question was if I can stop ObjectDatasource refresh data on every
postback.
I know I can do it in my button.click eventhandler on my own. But then I
have to write
code for paging, sorting etc.

Read the question before You asnwer please.
 
3P said:
Yeah this code works when I want to do it on button click. LOL.

I see that you have blinders on and can only see black or white. There
are no other colors that you see, huh?
I feel that You think that I don't anything about programming. But still
give me responses that have nothing to do with my problem.

That IsPostback is good for binding at the PageLoad not the button click.

You are wrong. It's a one time bind of data to the control on the page
load, and it doesn't bind anymore on the postback. Or don't you
understand that? Don't you understand to load the control at page_Load
on postback and first time load of the control with data.

And if you tell me that the control can only be loaded on user clicking
a button at application start, then it's ridiculous and totally unuser
friendly.
And the question was if I can stop ObjectDatasource refresh data on
every postback.

How are you going to tell a OBJECTDATASOURCE that you bound at the
ASP.aspx to NOT go back to the database on a POSTBACK? YOU CAN'T DO IT!

You had better come-up with something else, flip the script, as there is
no magic bullet in sight for you.
I know I can do it in my button.click eventhandler on my own. But then I
have to write
code for paging, sorting etc.

Read the question before You asnwer please.

You find that magic bullet you're not going to find, please.

Your compression to think outside the box and take another path is
suspect, and you need to flip the script if you can.
 
3P wrote:

<snipped>

One other thing, there is a magic bullet for you where you take complete
control of the datasource and how it gets data.

But that would require you to 'think outside the box' and figure out
this. How can I tell the datasource to not give me back the data, since
I am the one programming it and give it back when I tell it to give it
back. Can I pass a parm to it?

<copied>

Note that these methods are completely customizable and provides the
platform for adding custom business logic,
which was always missing earlier while binding the UI Layer directly
using SQL DataSource, LINQ DataSource etc.

<end copy>

This applies to VS 2008 too.

<http://geekswithblogs.net/ranganh/a...ithout-silverlight-in-visual-studio-2010.aspx>
<http://msdn.microsoft.com/en-us/library/ee707344(VS.91).aspx>

You don't need physical n-tier separation to do it, but rater logical
n-tier separation on the same Web server.

I know what you're talking about. But do you know what I am talking about?
 
Dnia 19-03-2010 o 19:32:15 Mr. Arnold said:
I see that you have blinders on and can only see black or white. There
are no other colors that you see, huh?


You are wrong. It's a one time bind of data to the control on the page
load, and it doesn't bind anymore on the postback. Or don't you
understand that? Don't you understand to load the control at page_Load
on postback and first time load of the control with data.
And where do You do one time bind of data if not in PageLoad?

How if (!IsPostback) is used in Button.Click? Please show.
And if you tell me that the control can only be loaded on user clicking
a button at application start, then it's ridiculous and totally unuser
friendly.
What? That was very simple. Setup filter then presh show me the data.
Then setup new filter and press show me the data again.
What is "unuser friendly"? (whatever that means).

How are you going to tell a OBJECTDATASOURCE that you bound at the
ASP.aspx to NOT go back to the database on a POSTBACK? YOU CAN'T DO IT!

I can handle Selecting event and set e.Cancel = true; and it doesn't hit
the database

Nevermind now. The only way to do it is inherit from GridView control and
override
InitializePager. Then I can do

btn_Click(...)
{
grid.NumberOfRows = sth;
grid.Datasource = ds;
grid.DataBind();
}

grid doesn't provide "NumberOfRows" property so You have to inherit from
it to add it.
 
3P said:
And where do You do one time bind of data if not in PageLoad?

How if (!IsPostback) is used in Button.Click? Please show.

The !IsPostback is about loading the control the very first time the
page is loaded with the control loaded and page rendered. You could have
passed some kind of initial filter to the dataload and loaded the
control out the gate.

There is nothing worst than a page coming up the first time the page is
loaded and a control such as a gridview is blank. And then I the user
must set a filter and load it the first time with a button?

The ispostback has NOTHING to do with your button-click. But it's a way
of making the page more user friendly so the user doesn't have to do
some ridiculous button-click to initially load the control. It should
already be loaded initially.
What? That was very simple. Setup filter then presh show me the data.
Then setup new filter and press show me the data again.
What is "unuser friendly"? (whatever that means).

It's ridiculous, and if I were the end-user or quality tester, it would
certainly hit the trash can as unnecessary functionality. The control
should have been initially loaded with data.
I can handle Selecting event and set e.Cancel = true; and it doesn't hit
the database

Why would you be selecting a row, and the selection of the row causes it
to go back to the database? It seems to me that event needs to be disabled.
Nevermind now. The only way to do it is inherit from GridView control
and override
InitializePager. Then I can do

btn_Click(...)
{
grid.NumberOfRows = sth;
grid.Datasource = ds;
grid.DataBind();
}

grid doesn't provide "NumberOfRows" property so You have to inherit from
it to add it.

Not to be smart here, I wouldn't waste my time on it, and I would take
control of the paging myself using a algorithm and using
PageIndexedChanged event to control paging. Or on NeededDataSource and
control paging there. I don't know if .Net controls have the event, like
RadCcontrols.
 
And where do You do one time bind of data if not in PageLoad?
The !IsPostback is about loading the control the very first time the
page is loaded with the control loaded and page rendered. You could have
passed some kind of initial filter to the dataload and loaded the
control out the gate.

And I said about loding it at the button click not at the PageLoad right?
There is nothing worst than a page coming up the first time the page is
loaded and a control such as a gridview is blank. And then I the user
must set a filter and load it the first time with a button?

Total nonsense. Database contains hundreds of tousands or records. Why
waste
users time, hit the database, and show him the data that he doesn't want?
And did You think for a second that this may be what user required?
Showing data after button click?
The ispostback has NOTHING to do with your button-click. But it's a way
of making the page more user friendly so the user doesn't have to do
some ridiculous button-click to initially load the control. It should
already be loaded initially.
Yeah run some SQL on 1 mil records and display without any filter. User
has to wait
for page to load and then still has to set the filter to se the data that
he's interested in.
What application start? Do You understand english at all? Have You seen
any form
containing filter on top of it and then grid showing data filtered with
this filter?
It's ridiculous, and if I were the end-user or quality tester, it would
certainly hit the trash can as unnecessary functionality. The control
should have been initially loaded with data.
And if I were I would ask why this page loads so slow and why does it show
me data
I dont give a f... about. And I would ask why the hell did You make it
show data
when I told you to do it on button click.
Why would you be selecting a row, and the selection of the row causes it
to go back to the database? It seems to me that event needs to be
disabled.

Who is talking about selecting a row!? And where? You clearly have no idea
what You talking about.
Not to be smart here, I wouldn't waste my time on it, and I would take
control of the paging myself using a algorithm and using
PageIndexedChanged event to control paging. Or on NeededDataSource and
control paging there. I don't know if .Net controls have the event, like
RadCcontrols.

Yeah and write Your custom grid from scratch and pager control. There is
no way
to tell the grid how many pages to display in pager other then using
ObjectDataSource
or by inheriting from GridView.
 
3P said:
And I said about loding it at the button click not at the PageLoad right?

Again not user friendly missing initial pageload and loading that control
Total nonsense. Database contains hundreds of tousands or records. Why
waste
users time,

I guess you never heard of a Select Where or Like statement.

hit the database, and show him the data that he doesn't want?
You never ask the user if the first page loads that there can be a
staring point on limited data shown? Who said anything about pulling 100
of thousand of records?
And did You think for a second that this may be what user required?
Showing data after button click?

You think it's ridiculous to give the user a starting point? What's with
your filter and limiting what gets shown first? It's better than a
double button-clicking. And you asked the users or the one power user of
the application or anybody in quality assurance about functionality?
Yeah run some SQL on 1 mil records and display without any filter. User
has to wait
for page to load and then still has to set the filter to se the data that
he's interested in.

What application start? Do You understand english at all? Have You seen
any form
containing filter on top of it and then grid showing data filtered with
this filter?

At one point, there was something on a response.redirect or
server.transfer that initially started that page initial application
start. Do you understand anything period is the question?
And if I were I would ask why this page loads so slow and why does it
show me data
I dont give a f... about. And I would ask why the hell did You make it
show data
when I told you to do it on button click.

LOL, this is one of you can't think out side the box, and give the
illusion of speed.
Who is talking about selecting a row!? And where? You clearly have no idea
what You talking about.

What? You're talking about the SelectedIndexChanged? There are not that
many events on the controls. And most of them are about the same. Don't
think that you're some of expert on controls now.

And even at that, based on any type of event fired, why is it attempting
to go back to the database, period, and you have to cancel up out of it.
:) There is something wrong there. You got AutoPostBack on the control
enabled? Maybe, you need to disable that too. :)

Like the health care bill, maybe you need to start over. :)

I have forgotten more in my approaching some 40 years in professional
programming in CICS, TSO, Windows desktop and Web controls than I care
to mention, but I am not expert.
Yeah and write Your custom grid from scratch and pager control. There is
no way
to tell the grid how many pages to display in pager other then using
ObjectDataSource
or by inheriting from GridView.

LOL, you have no clue as to what I am talking about, and you have not
been down the path I have walked.

A simple algorithm in the PageIndexed change event to compute how many
pages and items per page which are properties of the control preset in
the aspx HTML control is no big deal when you using Linq and Entity
Framework over a WCF Web service with 'objects' in a collection :)

Or you can use a WCF RIA service -- wink. :)
 
3P said:
Yeah run some SQL on 1 mil records and display without any filter. User
has to wait
for page to load and then still has to set the filter to se the data that
he's interested in.


About this, you run some SQL that selects 1m records. It seems like
something you might do, based on our conversation to this point.

In the meantime, I'll use ADO.NET Entity Framework, Linq-2-Objects and
query on selection criteria to get a subset out of the 1m records.
Maybe, I only comeback 20 records out of the 1m, an illusion of speed --
wink.
 
Dnia 20-03-2010 o 00:17:09 Mr. Arnold said:
Again not user friendly missing initial pageload and loading that control

Customer says I don't want initiali data. Do You understand it? Or do You
tell customer
to get the f... out and that You won't do any software for them?

Poor You. The only software You create is for your fun.
I guess you never heard of a Select Where or Like statement.
And what where clause You build if there is no filter specified? And so
what that
there is where and like if You still run it when client didn't specify
what he wants.
Yeah run LIKE on 1 mil records when nobody wants it. LOL.
hit the database, and show him the data that he doesn't want?
You never ask the user if the first page loads that there can be a
staring point on limited data shown? Who said anything about pulling 100
of thousand of records?


You think it's ridiculous to give the user a starting point? What's with
your filter and limiting what gets shown first? It's better than a
double button-clicking. And you asked the users or the one power user of
the application or anybody in quality assurance about functionality?
Reread this sentence. Or learn english!
At one point, there was something on a response.redirect or
server.transfer that initially started that page initial application
start. Do you understand anything period is the question?
No I don't understand Your english. And I don't understand what
response.redirect
or server.transfer You talk about.
LOL, this is one of you can't think out side the box, and give the
illusion of speed.
No it's give what client asks for. Keep doing software for fun.
What? You're talking about the SelectedIndexChanged? There are not that
many events on the controls. And most of them are about the same. Don't
think that you're some of expert on controls now.
Now You made me laugh. You really don't know what were talking about here.
What selectedIndexChanged? Can You read? Why would I hit the database on
SelectedIndexChanged?
I'll help You. We were talking about ObjectDataSource. Now get it?

And even at that, based on any type of event fired, why is it attempting
to go back to the database, period, and you have to cancel up out of it.
:) There is something wrong there. You got AutoPostBack on the control
enabled? Maybe, you need to disable that too. :)
Because ObjectDataSource does it. RTFM!
And there are many AutoPostback controls in filter, because gues what?
They have
to postback to populate dome dropdowns in filter.
Like the health care bill, maybe you need to start over. :)

I have forgotten more in my approaching some 40 years in professional
programming in CICS, TSO, Windows desktop and Web controls than I care
to mention, but I am not expert.


LOL, you have no clue as to what I am talking about, and you have not
been down the path I have walked.

A simple algorithm in the PageIndexed change event to compute how many
pages and items per page which are properties of the control preset in
the aspx HTML control is no big deal when you using Linq and Entity
Framework over a WCF Web service with 'objects' in a collection :)

Or you can use a WCF RIA service -- wink. :)

And if your not using EF, WCF or WCR RIA it is hard to calculate it!?

LOL. I see You know some technology terms. LOL. OK I will rebuild my app
use
EF, and WCF services to enable paging. Now I'm wondering if Your kidding
or ...

You can't set properties of a grid's pager! Understand? And that's
interesting if You calculate
how many items per page there is.
 
3P said:
I would like to create a very simple form.

When client enters it he has a filter to set. Then push the button get the
data and display in GridView.

Stick a parameter on your objectdatasource.
You can connect that up to whatever control you use to define the filter.
Make the initial selection something won't return anything.
OK it "hits your database" first time off but returns nuthin.

Or have your objectdatasource set up like this but only connect it to your
grid on first postback.
 
There is also the ObjectDataSource.DataBinding event that fires just before
the datasource is bound to a control. You can do any checks, canceling or
filtering here if you want.
 
I found a nice amongst the nasty. Nice in no way being an indicator of elegance...

Objectdatasource has Selecting method, which carries the parameters as a dictionary. One can either Cancel the select or mess with the parameter values.



Ps. much is lost when you give a monkey a [C]# spoon. Lose-th the monkey... lose-th the spoon.
 
I found a nice amongst the nasty. Nice in no way being an indicator of elegance...

Objectdatasource has Selecting method, which carries the parameters as a dictionary. One can either Cancel the select or mess with the parameter values.



Ps. much is lost when you give a monkey a [C]# spoon. Lose-th the monkey... lose-th the spoon.
I would like to create a very simple form.

When client enters it he has a filter to set. Then push the button get the
data and display in GridView.
Grid uses ObjectDataSource and allows paging and sorting (using custom
stored proc returning only data needed on current page).
But seems that ObjectDataSource is refreshing data on every postback. it is
not ok because dropdowns in
filter also postback thus I hit the database and display data before
filter is set and before client
pushes the button. Plus it hits the database on first PageLoad.

Is there any way to prevent such a behaviour of ObjectDataSource? Or is
there a way to do it w/o ObjectDatasource?
Other then inheriting from GridView and overriding InitializePager (or sth
like that). I cannot find a way to tell
the grid how many records there is so it can generate the Pager.

I thought I found the solution by handling the Selecting event and
canceling it until user pushes the button. But when
there is data in grid and I cancel Selecting event the data in grid is
cleared :/

If it is not possible with ObjectDataSource, then I really do not know what
this control is for. Then it is totally unusable
for other then maybe one or two simplest solutions.


3P
What are you talking about here? You do not want to go back to the database?
Objectdatasource has Selecting method, which carries the parameters as a dictionary. One can either Cancel the select or mess with the parameter values.







Ps. much is lost when you give a monkey a [C]# spoon. Lose-th the monkey... lose-th the spoon.
 
Back
Top