By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,647 Members | 1,618 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,647 IT Pros & Developers. It's quick & easy.

Page_Load

P: n/a
Hi.

I have a button called btnSelect on a web form. There is a handler for it.
However, the Page_Load() gets called before the handler gets called.

I want to do the following. In the Page_Load(), I want to check if the
btnSelect caused the event. How can I do this?

Please help.

--
Be Cool!
Jul 21 '05 #1
Share this Question
Share on Google+
16 Replies


P: n/a
Take a look at the values available int Request object; you should be able
to find the information you need because all the information send by the
POST submission of the form is there.

However, I'm not sure is this is the right thing to do. Instead, you should
isolate the relevant code in a subroutine and call it from the btnSelect
event.

S. L.

"thejackofall" <th**********@discussions.microsoft.com> wrote in message
news:B8**********************************@microsof t.com...
Hi.

I have a button called btnSelect on a web form. There is a handler for
it.
However, the Page_Load() gets called before the handler gets called.

I want to do the following. In the Page_Load(), I want to check if the
btnSelect caused the event. How can I do this?

Please help.

--
Be Cool!

Jul 21 '05 #2

P: n/a
Yes. You are right about the form submission with the post. I can get the
information. However, this is a little different story.

This has more to do with postback and capturing events.

The question is, "How do I check what object caused this event for it to
come to Page_Load()?".

Please help.

"Sylvain Lafontaine" wrote:
Take a look at the values available int Request object; you should be able
to find the information you need because all the information send by the
POST submission of the form is there.

However, I'm not sure is this is the right thing to do. Instead, you should
isolate the relevant code in a subroutine and call it from the btnSelect
event.

S. L.

"thejackofall" <th**********@discussions.microsoft.com> wrote in message
news:B8**********************************@microsof t.com...
Hi.

I have a button called btnSelect on a web form. There is a handler for
it.
However, the Page_Load() gets called before the handler gets called.

I want to do the following. In the Page_Load(), I want to check if the
btnSelect caused the event. How can I do this?

Please help.

--
Be Cool!


Jul 21 '05 #3

P: n/a
I'm sorry, but I don't know the answer to your question.

Maybe the following article will give you a starting point for your
research:
http://msdn.microsoft.com/library/de...bjectmodel.asp

S. L.

"thejackofall" <th**********@discussions.microsoft.com> wrote in message
news:37**********************************@microsof t.com...
Yes. You are right about the form submission with the post. I can get
the
information. However, this is a little different story.

This has more to do with postback and capturing events.

The question is, "How do I check what object caused this event for it to
come to Page_Load()?".

Please help.

"Sylvain Lafontaine" wrote:
Take a look at the values available int Request object; you should be
able
to find the information you need because all the information send by the
POST submission of the form is there.

However, I'm not sure is this is the right thing to do. Instead, you
should
isolate the relevant code in a subroutine and call it from the btnSelect
event.

S. L.

"thejackofall" <th**********@discussions.microsoft.com> wrote in message
news:B8**********************************@microsof t.com...
> Hi.
>
> I have a button called btnSelect on a web form. There is a handler
> for
> it.
> However, the Page_Load() gets called before the handler gets called.
>
> I want to do the following. In the Page_Load(), I want to check if the
> btnSelect caused the event. How can I do this?
>
> Please help.
>
> --
> Be Cool!


Jul 21 '05 #4

P: n/a
Hi

The loadevent is called everytime a page is loaded or/and is postedback

There is no need to check in that page the handling of the button event,
that you can do in the button click event it self (when you do not know
that, than message back)

For to prevent that unwanted actions are taken on postback is the IsPostback
property, very easy to use and well desctripted on this page.
http://msdn.microsoft.com/library/de...tbacktopic.asp

I hope this helps?

Merry Christmas

Cor
Jul 21 '05 #5

P: n/a
Cor,

Here is my problem. I have a datagrid with sort columns. One of those
columns is a checkbox column. And, I have a button regular button with
postback.

My page_load() looks something like this:

void page_load(..)
{
If (!IsPostBack)
{
Session["SortColumn"] = "AgentID";
Session["SortOrder"] = "Asc";
}

BindData();
}

When I click on a column header, it sorts by the sort order. So, I need to
call BindData(). When I click on a button called "Select", I don't need to
call BindData() and display the checkboxes that are checked prior to pressing
the button. I do have the button handler, but the Page_Load is called before
the handler gets called.

I need to determine if the original event is caused by the button or
something else in order to prevent the datagrid binding data every time.

Your input is appreciated.

J

"Cor Ligthert" wrote:
Hi

The loadevent is called everytime a page is loaded or/and is postedback

There is no need to check in that page the handling of the button event,
that you can do in the button click event it self (when you do not know
that, than message back)

For to prevent that unwanted actions are taken on postback is the IsPostback
property, very easy to use and well desctripted on this page.
http://msdn.microsoft.com/library/de...tbacktopic.asp

I hope this helps?

Merry Christmas

Cor

Jul 21 '05 #6

P: n/a
J,

Probably when you see this than you think something as Ohhhh me

My page_load() looks something like this:

void page_load(..)
{
If (!IsPostBack)
{
Session["SortColumn"] = "AgentID";
Session["SortOrder"] = "Asc";

BindData();
}
}

And you do the BindData() as normal in your clickevent at the time when it
should be done.

I hope this helps?

Cor
Jul 21 '05 #7

P: n/a
Cor is right. Move BindData into your if statement and then call it as
needed in the click event for the column sort.
Then, when the user clicks select, you won't run into a BindData call along
the way.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"thejackofall" <th**********@discussions.microsoft.com> wrote in message
news:7B**********************************@microsof t.com...
Cor,

Here is my problem. I have a datagrid with sort columns. One of those
columns is a checkbox column. And, I have a button regular button with
postback.

My page_load() looks something like this:

void page_load(..)
{
If (!IsPostBack)
{
Session["SortColumn"] = "AgentID";
Session["SortOrder"] = "Asc";
}

BindData();
}

When I click on a column header, it sorts by the sort order. So, I need to call BindData(). When I click on a button called "Select", I don't need to call BindData() and display the checkboxes that are checked prior to pressing the button. I do have the button handler, but the Page_Load is called before the handler gets called.

I need to determine if the original event is caused by the button or
something else in order to prevent the datagrid binding data every time.

Your input is appreciated.

J

"Cor Ligthert" wrote:
Hi

The loadevent is called everytime a page is loaded or/and is postedback

There is no need to check in that page the handling of the button event,
that you can do in the button click event it self (when you do not know
that, than message back)

For to prevent that unwanted actions are taken on postback is the IsPostback property, very easy to use and well desctripted on this page.
http://msdn.microsoft.com/library/de...tbacktopic.asp
I hope this helps?

Merry Christmas

Cor

Jul 21 '05 #8

P: n/a
Aha! It's a good try, but here is something to consider. If I move the
BindData() to the !IsPostBack section, and then, I press a column header, it
won't show any data because BindData() isn't being called. SOmehow, I need
to prevent BindData() only when it is caused by the "select" button.

J

"Nick Malik [Microsoft]" wrote:
Cor is right. Move BindData into your if statement and then call it as
needed in the click event for the column sort.
Then, when the user clicks select, you won't run into a BindData call along
the way.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"thejackofall" <th**********@discussions.microsoft.com> wrote in message
news:7B**********************************@microsof t.com...
Cor,

Here is my problem. I have a datagrid with sort columns. One of those
columns is a checkbox column. And, I have a button regular button with
postback.

My page_load() looks something like this:

void page_load(..)
{
If (!IsPostBack)
{
Session["SortColumn"] = "AgentID";
Session["SortOrder"] = "Asc";
}

BindData();
}

When I click on a column header, it sorts by the sort order. So, I need

to
call BindData(). When I click on a button called "Select", I don't need

to
call BindData() and display the checkboxes that are checked prior to

pressing
the button. I do have the button handler, but the Page_Load is called

before
the handler gets called.

I need to determine if the original event is caused by the button or
something else in order to prevent the datagrid binding data every time.

Your input is appreciated.

J

"Cor Ligthert" wrote:
Hi

The loadevent is called everytime a page is loaded or/and is postedback

There is no need to check in that page the handling of the button event,
that you can do in the button click event it self (when you do not know
that, than message back)

For to prevent that unwanted actions are taken on postback is the IsPostback property, very easy to use and well desctripted on this page.
http://msdn.microsoft.com/library/de...tbacktopic.asp
I hope this helps?

Merry Christmas

Cor


Jul 21 '05 #9

P: n/a
Oh, OK. I mis-uderstood earlier. That may work. LEt me try it and get back
to this.

Thanks much.

"thejackofall" wrote:
Aha! It's a good try, but here is something to consider. If I move the
BindData() to the !IsPostBack section, and then, I press a column header, it
won't show any data because BindData() isn't being called. SOmehow, I need
to prevent BindData() only when it is caused by the "select" button.

J

"Nick Malik [Microsoft]" wrote:
Cor is right. Move BindData into your if statement and then call it as
needed in the click event for the column sort.
Then, when the user clicks select, you won't run into a BindData call along
the way.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"thejackofall" <th**********@discussions.microsoft.com> wrote in message
news:7B**********************************@microsof t.com...
Cor,

Here is my problem. I have a datagrid with sort columns. One of those
columns is a checkbox column. And, I have a button regular button with
postback.

My page_load() looks something like this:

void page_load(..)
{
If (!IsPostBack)
{
Session["SortColumn"] = "AgentID";
Session["SortOrder"] = "Asc";
}

BindData();
}

When I click on a column header, it sorts by the sort order. So, I need

to
call BindData(). When I click on a button called "Select", I don't need

to
call BindData() and display the checkboxes that are checked prior to

pressing
the button. I do have the button handler, but the Page_Load is called

before
the handler gets called.

I need to determine if the original event is caused by the button or
something else in order to prevent the datagrid binding data every time.

Your input is appreciated.

J

"Cor Ligthert" wrote:

> Hi
>
> The loadevent is called everytime a page is loaded or/and is postedback
>
> There is no need to check in that page the handling of the button event,
> that you can do in the button click event it self (when you do not know
> that, than message back)
>
> For to prevent that unwanted actions are taken on postback is the

IsPostback
> property, very easy to use and well desctripted on this page.
>

http://msdn.microsoft.com/library/de...tbacktopic.asp
>
> I hope this helps?
>
> Merry Christmas
>
> Cor
>
>
>


Jul 21 '05 #10

P: n/a
Thanks for the suggestion. I did stick the BindData() in the !isPostBack
block. In the process, I learned that my columns were sorting only because
BindData() was called everytime. Since I moved BindData() into the
!IsPostBack block, my columns don't sort when I click on a column header. I
learned that TemplateColumn does not generate the sort event.

I need to be able to sort using the TemplateColumn. Please help.

Thanks
TheJackOfAll

"Cor Ligthert" wrote:
J,

Probably when you see this than you think something as Ohhhh me

My page_load() looks something like this:

void page_load(..)
{
If (!IsPostBack)
{
Session["SortColumn"] = "AgentID";
Session["SortOrder"] = "Asc";

BindData();
}
}

And you do the BindData() as normal in your clickevent at the time when it
should be done.

I hope this helps?

Cor

Jul 21 '05 #11

P: n/a
Thanks for the suggestion. I did stick the BindData() in the !isPostBack
block. In the process, I learned that my columns were sorting only because
BindData() was called everytime. Since I moved BindData() into the
!IsPostBack block, my columns don't sort when I click on a column header. I
learned that TemplateColumn does not generate the sort event.

Does anyone have any helpful information to sort when using TemplateColumn?

I need to be able to sort using the TemplateColumn. Please help.

Thanks
TheJackOfAll

"Nick Malik [Microsoft]" wrote:
Cor is right. Move BindData into your if statement and then call it as
needed in the click event for the column sort.
Then, when the user clicks select, you won't run into a BindData call along
the way.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"thejackofall" <th**********@discussions.microsoft.com> wrote in message
news:7B**********************************@microsof t.com...
Cor,

Here is my problem. I have a datagrid with sort columns. One of those
columns is a checkbox column. And, I have a button regular button with
postback.

My page_load() looks something like this:

void page_load(..)
{
If (!IsPostBack)
{
Session["SortColumn"] = "AgentID";
Session["SortOrder"] = "Asc";
}

BindData();
}

When I click on a column header, it sorts by the sort order. So, I need

to
call BindData(). When I click on a button called "Select", I don't need

to
call BindData() and display the checkboxes that are checked prior to

pressing
the button. I do have the button handler, but the Page_Load is called

before
the handler gets called.

I need to determine if the original event is caused by the button or
something else in order to prevent the datagrid binding data every time.

Your input is appreciated.

J

"Cor Ligthert" wrote:
Hi

The loadevent is called everytime a page is loaded or/and is postedback

There is no need to check in that page the handling of the button event,
that you can do in the button click event it self (when you do not know
that, than message back)

For to prevent that unwanted actions are taken on postback is the IsPostback property, very easy to use and well desctripted on this page.
http://msdn.microsoft.com/library/de...tbacktopic.asp
I hope this helps?

Merry Christmas

Cor


Jul 21 '05 #12

P: n/a
Jack,

On what other places did you do the databind, because you have probably to
do the databind in most of your events.

From your post I am still not sure you do that?

Show us some more code, especially from an event where you do some actions
with your sortcode session.

Cor
Jul 21 '05 #13

P: n/a
both Cor and I asked you to move the BindData into the PostBack and then
ALSO call BindData in each of the events where you want the sort to occur.

I'm not sure that you understood that.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"thejackofall" <th**********@discussions.microsoft.com> wrote in message
news:38**********************************@microsof t.com...
Thanks for the suggestion. I did stick the BindData() in the !isPostBack
block. In the process, I learned that my columns were sorting only because BindData() was called everytime. Since I moved BindData() into the
!IsPostBack block, my columns don't sort when I click on a column header. I learned that TemplateColumn does not generate the sort event.

Does anyone have any helpful information to sort when using TemplateColumn?
I need to be able to sort using the TemplateColumn. Please help.

Thanks
TheJackOfAll

"Nick Malik [Microsoft]" wrote:
Cor is right. Move BindData into your if statement and then call it as
needed in the click event for the column sort.
Then, when the user clicks select, you won't run into a BindData call along
the way.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"thejackofall" <th**********@discussions.microsoft.com> wrote in message
news:7B**********************************@microsof t.com...
Cor,

Here is my problem. I have a datagrid with sort columns. One of those columns is a checkbox column. And, I have a button regular button with postback.

My page_load() looks something like this:

void page_load(..)
{
If (!IsPostBack)
{
Session["SortColumn"] = "AgentID";
Session["SortOrder"] = "Asc";
}

BindData();
}

When I click on a column header, it sorts by the sort order. So, I need
to
call BindData(). When I click on a button called "Select", I don't
need to
call BindData() and display the checkboxes that are checked prior to

pressing
the button. I do have the button handler, but the Page_Load is called

before
the handler gets called.

I need to determine if the original event is caused by the button or
something else in order to prevent the datagrid binding data every

time.
Your input is appreciated.

J

"Cor Ligthert" wrote:

> Hi
>
> The loadevent is called everytime a page is loaded or/and is postedback >
> There is no need to check in that page the handling of the button event, > that you can do in the button click event it self (when you do not know > that, than message back)
>
> For to prevent that unwanted actions are taken on postback is the

IsPostback
> property, very easy to use and well desctripted on this page.
>

http://msdn.microsoft.com/library/de...tbacktopic.asp
>
> I hope this helps?
>
> Merry Christmas
>
> Cor
>
>
>


Jul 21 '05 #14

P: n/a
Yes. You are right about the approach. And, I did exactly what you guys
said. My problem, now is that I am using TemplateColumns, and the
TemplateColumn does not generate the event I need to do the sorting.

Thanks.
TheJackOfAll

"Nick Malik [Microsoft]" wrote:
both Cor and I asked you to move the BindData into the PostBack and then
ALSO call BindData in each of the events where you want the sort to occur.

I'm not sure that you understood that.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"thejackofall" <th**********@discussions.microsoft.com> wrote in message
news:38**********************************@microsof t.com...
Thanks for the suggestion. I did stick the BindData() in the !isPostBack
block. In the process, I learned that my columns were sorting only

because
BindData() was called everytime. Since I moved BindData() into the
!IsPostBack block, my columns don't sort when I click on a column header.

I
learned that TemplateColumn does not generate the sort event.

Does anyone have any helpful information to sort when using

TemplateColumn?

I need to be able to sort using the TemplateColumn. Please help.

Thanks
TheJackOfAll

"Nick Malik [Microsoft]" wrote:
Cor is right. Move BindData into your if statement and then call it as
needed in the click event for the column sort.
Then, when the user clicks select, you won't run into a BindData call along the way.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"thejackofall" <th**********@discussions.microsoft.com> wrote in message
news:7B**********************************@microsof t.com...
> Cor,
>
> Here is my problem. I have a datagrid with sort columns. One of those > columns is a checkbox column. And, I have a button regular button with > postback.
>
> My page_load() looks something like this:
>
> void page_load(..)
> {
> If (!IsPostBack)
> {
> Session["SortColumn"] = "AgentID";
> Session["SortOrder"] = "Asc";
> }
>
> BindData();
> }
>
> When I click on a column header, it sorts by the sort order. So, I need to
> call BindData(). When I click on a button called "Select", I don't need to
> call BindData() and display the checkboxes that are checked prior to
pressing
> the button. I do have the button handler, but the Page_Load is called
before
> the handler gets called.
>
> I need to determine if the original event is caused by the button or
> something else in order to prevent the datagrid binding data every time. >
> Your input is appreciated.
>
> J
>
> "Cor Ligthert" wrote:
>
> > Hi
> >
> > The loadevent is called everytime a page is loaded or/and is postedback > >
> > There is no need to check in that page the handling of the button event, > > that you can do in the button click event it self (when you do not know > > that, than message back)
> >
> > For to prevent that unwanted actions are taken on postback is the
IsPostback
> > property, very easy to use and well desctripted on this page.
> >
http://msdn.microsoft.com/library/de...tbacktopic.asp > >
> > I hope this helps?
> >
> > Merry Christmas
> >
> > Cor
> >
> >
> >


Jul 21 '05 #15

P: n/a
Hi. I have a TemplateColumn with sorting. However, it does not fire the
sort event. Here is what I have. Please help.

<asp:TemplateColumn HeaderText="Wire ID"
SortExpression="WireID">
<itemtemplate>
<a href='<%# "Wire.aspx" + "?PackageID=" +
Request.QueryString["PackageID"] + "&WireID=" +
DataBinder.Eval(Container.DataItem, "WireID") + "&AgentID=" +
DataBinder.Eval(Container.DataItem, "AgentID") + "&CustomerType=" +
DataBinder.Eval(Container.DataItem, "CustomerType") %>'>
<%# DataBinder.Eval(Container.DataItem, "WireID") %>
</a>
</itemtemplate>
</asp:TemplateColumn>

++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++

In the code behind,

private void InitializeComponent()
{
//this.lnkWireID = new LinkButton();
//this.lnkWireID.ID = "lnkWireID";

this.btnInclude.Click += new System.EventHandler(this.btnInclude_Click);
this.btnApprove.Click += new System.EventHandler(this.btnApprove_Click);
this.CustomerType.SelectedIndexChanged += new
System.EventHandler(this.CustomerType_SelectedInde xChanged);
this.DataGrid1.SortCommand += new
System.Web.UI.WebControls.DataGridSortCommandEvent Handler(this.SortData);
this.Load += new System.EventHandler(this.Page_Load);

}

++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++

private void SortData(Object sender, DataGridSortCommandEventArgs e)
{
Session["SortColumn"] = (string) e.SortExpression;
string sSortOrder = (string) Session["SortOrder"];

if (sSortOrder == " desc")
Session["SortOrder"] = " asc";
else
Session["SortOrder"] = " desc";

BindData();
}

Thanks
Jack
"thejackofall" wrote:
Yes. You are right about the approach. And, I did exactly what you guys
said. My problem, now is that I am using TemplateColumns, and the
TemplateColumn does not generate the event I need to do the sorting.

Thanks.
TheJackOfAll

"Nick Malik [Microsoft]" wrote:
both Cor and I asked you to move the BindData into the PostBack and then
ALSO call BindData in each of the events where you want the sort to occur.

I'm not sure that you understood that.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"thejackofall" <th**********@discussions.microsoft.com> wrote in message
news:38**********************************@microsof t.com...
Thanks for the suggestion. I did stick the BindData() in the !isPostBack
block. In the process, I learned that my columns were sorting only

because
BindData() was called everytime. Since I moved BindData() into the
!IsPostBack block, my columns don't sort when I click on a column header.

I
learned that TemplateColumn does not generate the sort event.

Does anyone have any helpful information to sort when using

TemplateColumn?

I need to be able to sort using the TemplateColumn. Please help.

Thanks
TheJackOfAll

"Nick Malik [Microsoft]" wrote:

> Cor is right. Move BindData into your if statement and then call it as
> needed in the click event for the column sort.
> Then, when the user clicks select, you won't run into a BindData call

along
> the way.
>
> --
> --- Nick Malik [Microsoft]
> MCSD, CFPS, Certified Scrummaster
> http://blogs.msdn.com/nickmalik
>
> Disclaimer: Opinions expressed in this forum are my own, and not
> representative of my employer.
> I do not answer questions on behalf of my employer. I'm just a
> programmer helping programmers.
> --
> "thejackofall" <th**********@discussions.microsoft.com> wrote in message
> news:7B**********************************@microsof t.com...
> > Cor,
> >
> > Here is my problem. I have a datagrid with sort columns. One of

those
> > columns is a checkbox column. And, I have a button regular button

with
> > postback.
> >
> > My page_load() looks something like this:
> >
> > void page_load(..)
> > {
> > If (!IsPostBack)
> > {
> > Session["SortColumn"] = "AgentID";
> > Session["SortOrder"] = "Asc";
> > }
> >
> > BindData();
> > }
> >
> > When I click on a column header, it sorts by the sort order. So, I

need
> to
> > call BindData(). When I click on a button called "Select", I don't

need
> to
> > call BindData() and display the checkboxes that are checked prior to
> pressing
> > the button. I do have the button handler, but the Page_Load is called
> before
> > the handler gets called.
> >
> > I need to determine if the original event is caused by the button or
> > something else in order to prevent the datagrid binding data every

time.
> >
> > Your input is appreciated.
> >
> > J
> >
> > "Cor Ligthert" wrote:
> >
> > > Hi
> > >
> > > The loadevent is called everytime a page is loaded or/and is

postedback
> > >
> > > There is no need to check in that page the handling of the button

event,
> > > that you can do in the button click event it self (when you do not

know
> > > that, than message back)
> > >
> > > For to prevent that unwanted actions are taken on postback is the
> IsPostback
> > > property, very easy to use and well desctripted on this page.
> > >
>

http://msdn.microsoft.com/library/de...tbacktopic.asp
> > >
> > > I hope this helps?
> > >
> > > Merry Christmas
> > >
> > > Cor
> > >
> > >
> > >
>
>
>


Jul 21 '05 #16

P: n/a
Hi. I have a TemplateColumn with sorting. However, it does not fire the
sort event. Here is what I have. Please help.

<asp:TemplateColumn HeaderText="Wire ID"
SortExpression="WireID">
<itemtemplate>
<a href='<%# "Wire.aspx" + "?PackageID=" +
Request.QueryString["PackageID"] + "&WireID=" +
DataBinder.Eval(Container.DataItem, "WireID") + "&AgentID=" +
DataBinder.Eval(Container.DataItem, "AgentID") + "&CustomerType=" +
DataBinder.Eval(Container.DataItem, "CustomerType") %>'>
<%# DataBinder.Eval(Container.DataItem, "WireID") %>
</a>
</itemtemplate>
</asp:TemplateColumn>

++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++

In the code behind,

private void InitializeComponent()
{
//this.lnkWireID = new LinkButton();
//this.lnkWireID.ID = "lnkWireID";

this.btnInclude.Click += new System.EventHandler(this.btnInclude_Click);
this.btnApprove.Click += new System.EventHandler(this.btnApprove_Click);
this.CustomerType.SelectedIndexChanged += new
System.EventHandler(this.CustomerType_SelectedInde xChanged);
this.DataGrid1.SortCommand += new
System.Web.UI.WebControls.DataGridSortCommandEvent Handler(this.SortData);
this.Load += new System.EventHandler(this.Page_Load);

}

++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++

private void SortData(Object sender, DataGridSortCommandEventArgs e)
{
Session["SortColumn"] = (string) e.SortExpression;
string sSortOrder = (string) Session["SortOrder"];

if (sSortOrder == " desc")
Session["SortOrder"] = " asc";
else
Session["SortOrder"] = " desc";

BindData();
}

Thanks
Jack
"thejackofall" wrote:
Yes. You are right about the approach. And, I did exactly what you guys
said. My problem, now is that I am using TemplateColumns, and the
TemplateColumn does not generate the event I need to do the sorting.

Thanks.
TheJackOfAll

"Nick Malik [Microsoft]" wrote:
both Cor and I asked you to move the BindData into the PostBack and then
ALSO call BindData in each of the events where you want the sort to occur.

I'm not sure that you understood that.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"thejackofall" <th**********@discussions.microsoft.com> wrote in message
news:38**********************************@microsof t.com...
Thanks for the suggestion. I did stick the BindData() in the !isPostBack
block. In the process, I learned that my columns were sorting only

because
BindData() was called everytime. Since I moved BindData() into the
!IsPostBack block, my columns don't sort when I click on a column header.

I
learned that TemplateColumn does not generate the sort event.

Does anyone have any helpful information to sort when using

TemplateColumn?

I need to be able to sort using the TemplateColumn. Please help.

Thanks
TheJackOfAll

"Nick Malik [Microsoft]" wrote:

> Cor is right. Move BindData into your if statement and then call it as
> needed in the click event for the column sort.
> Then, when the user clicks select, you won't run into a BindData call

along
> the way.
>
> --
> --- Nick Malik [Microsoft]
> MCSD, CFPS, Certified Scrummaster
> http://blogs.msdn.com/nickmalik
>
> Disclaimer: Opinions expressed in this forum are my own, and not
> representative of my employer.
> I do not answer questions on behalf of my employer. I'm just a
> programmer helping programmers.
> --
> "thejackofall" <th**********@discussions.microsoft.com> wrote in message
> news:7B**********************************@microsof t.com...
> > Cor,
> >
> > Here is my problem. I have a datagrid with sort columns. One of

those
> > columns is a checkbox column. And, I have a button regular button

with
> > postback.
> >
> > My page_load() looks something like this:
> >
> > void page_load(..)
> > {
> > If (!IsPostBack)
> > {
> > Session["SortColumn"] = "AgentID";
> > Session["SortOrder"] = "Asc";
> > }
> >
> > BindData();
> > }
> >
> > When I click on a column header, it sorts by the sort order. So, I

need
> to
> > call BindData(). When I click on a button called "Select", I don't

need
> to
> > call BindData() and display the checkboxes that are checked prior to
> pressing
> > the button. I do have the button handler, but the Page_Load is called
> before
> > the handler gets called.
> >
> > I need to determine if the original event is caused by the button or
> > something else in order to prevent the datagrid binding data every

time.
> >
> > Your input is appreciated.
> >
> > J
> >
> > "Cor Ligthert" wrote:
> >
> > > Hi
> > >
> > > The loadevent is called everytime a page is loaded or/and is

postedback
> > >
> > > There is no need to check in that page the handling of the button

event,
> > > that you can do in the button click event it self (when you do not

know
> > > that, than message back)
> > >
> > > For to prevent that unwanted actions are taken on postback is the
> IsPostback
> > > property, very easy to use and well desctripted on this page.
> > >
>

http://msdn.microsoft.com/library/de...tbacktopic.asp
> > >
> > > I hope this helps?
> > >
> > > Merry Christmas
> > >
> > > Cor
> > >
> > >
> > >
>
>
>


Jul 21 '05 #17

This discussion thread is closed

Replies have been disabled for this discussion.