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

Button events

P: n/a
Hi,

I have created a control with some buttons an alphabet. When one of these
buttons are pressed it posts back and in the postback event for the button
pressed a list of tems is created with a list of buttons next to them to
delete the term. My problem is that the delete button has a delete event
attached to it but t does not fire. Is this because the delete butons are
created in the postbaclk event and not the CreateChildControls method - and
if so how do I fix this.

Jim
Dec 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Jim:
The entire state of the page needs to be created when a button is clicked.
So when you press a delete button, you need to make sure that whatever
controls were loaded when a alphabet-button was clicked are loaded.

My guess is that the delete button isn't re-created on postback, so the
event never fires. A typical way to solve this is to store some info in the
viewstate. Here's some pseudocode:

sub AlphabetButton_click(...)
LoadYourTerms(e.CommandArgument)
ViewState.Add("Letter", e.CommandArgument)
end sub

sub page_load(...)
'IF we are posting back AND there's a letter stored in the viewstate
if Page.IsPostBack AndAlso not ViewState("Letter") is nothing then
LoadYourTerms(ViewState("Letter"))
end if
end sub
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Jimmy Jazz" <Ji*******@discussions.microsoft.com> wrote in message
news:7C**********************************@microsof t.com...
Hi,

I have created a control with some buttons an alphabet. When one of these
buttons are pressed it posts back and in the postback event for the button
pressed a list of tems is created with a list of buttons next to them to
delete the term. My problem is that the delete button has a delete event
attached to it but t does not fire. Is this because the delete butons are
created in the postbaclk event and not the CreateChildControls method -
and
if so how do I fix this.

Jim

Dec 20 '05 #2

P: n/a
Hi Karl,
I cannot load up the terms, in the control I created the letter selected is
not know until the

AlphabetButton_Click(...)

and all the controls have been written by then

Jim

"Karl Seguin" wrote:
Jim:
The entire state of the page needs to be created when a button is clicked.
So when you press a delete button, you need to make sure that whatever
controls were loaded when a alphabet-button was clicked are loaded.

My guess is that the delete button isn't re-created on postback, so the
event never fires. A typical way to solve this is to store some info in the
viewstate. Here's some pseudocode:

sub AlphabetButton_click(...)
LoadYourTerms(e.CommandArgument)
ViewState.Add("Letter", e.CommandArgument)
end sub

sub page_load(...)
'IF we are posting back AND there's a letter stored in the viewstate
if Page.IsPostBack AndAlso not ViewState("Letter") is nothing then
LoadYourTerms(ViewState("Letter"))
end if
end sub
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Jimmy Jazz" <Ji*******@discussions.microsoft.com> wrote in message
news:7C**********************************@microsof t.com...
Hi,

I have created a control with some buttons an alphabet. When one of these
buttons are pressed it posts back and in the postback event for the button
pressed a list of tems is created with a list of buttons next to them to
delete the term. My problem is that the delete button has a delete event
attached to it but t does not fire. Is this because the delete butons are
created in the postbaclk event and not the CreateChildControls method -
and
if so how do I fix this.

Jim


Dec 20 '05 #3

P: n/a
Not sure I understand.

There are a bunch of letters
User clicks one
There are a bunch of terms
User clicks one
Term is deleted
If you look at my example, every time a letter is clicked, that value is
stored in the viewstate. Your problem is that when a term is clicked, the
letter isn't reloaded, hence the term isn't deleted. In my example, the
value from the viewstate is read during Page_Load and the page is returned
to it's previous state.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Jimmy Jazz" <Ji*******@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
Hi Karl,
I cannot load up the terms, in the control I created the letter selected
is
not know until the

AlphabetButton_Click(...)

and all the controls have been written by then

Jim

"Karl Seguin" wrote:
Jim:
The entire state of the page needs to be created when a button is
clicked.
So when you press a delete button, you need to make sure that whatever
controls were loaded when a alphabet-button was clicked are loaded.

My guess is that the delete button isn't re-created on postback, so the
event never fires. A typical way to solve this is to store some info in
the
viewstate. Here's some pseudocode:

sub AlphabetButton_click(...)
LoadYourTerms(e.CommandArgument)
ViewState.Add("Letter", e.CommandArgument)
end sub

sub page_load(...)
'IF we are posting back AND there's a letter stored in the viewstate
if Page.IsPostBack AndAlso not ViewState("Letter") is nothing then
LoadYourTerms(ViewState("Letter"))
end if
end sub
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Jimmy Jazz" <Ji*******@discussions.microsoft.com> wrote in message
news:7C**********************************@microsof t.com...
> Hi,
>
> I have created a control with some buttons an alphabet. When one of
> these
> buttons are pressed it posts back and in the postback event for the
> button
> pressed a list of tems is created with a list of buttons next to them
> to
> delete the term. My problem is that the delete button has a delete
> event
> attached to it but t does not fire. Is this because the delete butons
> are
> created in the postbaclk event and not the CreateChildControls method -
> and
> if so how do I fix this.
>
> Jim


Dec 20 '05 #4

P: n/a
Hi Karl,

No not quiet, The control loads on CreateChildControls the alphabet buttons
are created with a ConnandEventHandler connected. Whan a user presses a
letter I use Viewstate to record the letter then show the terms and buttons
next to them with a ConnandEventHandler connected. When a delete button is
pressed it posts back but does not go into the EventHandler where the delete
functionality is held. Thas the problem

Jim
"Karl Seguin" wrote:
Not sure I understand.

There are a bunch of letters
User clicks one
There are a bunch of terms
User clicks one
Term is deleted
If you look at my example, every time a letter is clicked, that value is
stored in the viewstate. Your problem is that when a term is clicked, the
letter isn't reloaded, hence the term isn't deleted. In my example, the
value from the viewstate is read during Page_Load and the page is returned
to it's previous state.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Jimmy Jazz" <Ji*******@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
Hi Karl,
I cannot load up the terms, in the control I created the letter selected
is
not know until the

AlphabetButton_Click(...)

and all the controls have been written by then

Jim

"Karl Seguin" wrote:
Jim:
The entire state of the page needs to be created when a button is
clicked.
So when you press a delete button, you need to make sure that whatever
controls were loaded when a alphabet-button was clicked are loaded.

My guess is that the delete button isn't re-created on postback, so the
event never fires. A typical way to solve this is to store some info in
the
viewstate. Here's some pseudocode:

sub AlphabetButton_click(...)
LoadYourTerms(e.CommandArgument)
ViewState.Add("Letter", e.CommandArgument)
end sub

sub page_load(...)
'IF we are posting back AND there's a letter stored in the viewstate
if Page.IsPostBack AndAlso not ViewState("Letter") is nothing then
LoadYourTerms(ViewState("Letter"))
end if
end sub
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Jimmy Jazz" <Ji*******@discussions.microsoft.com> wrote in message
news:7C**********************************@microsof t.com...
> Hi,
>
> I have created a control with some buttons an alphabet. When one of
> these
> buttons are pressed it posts back and in the postback event for the
> button
> pressed a list of tems is created with a list of buttons next to them
> to
> delete the term. My problem is that the delete button has a delete
> event
> attached to it but t does not fire. Is this because the delete butons
> are
> created in the postbaclk event and not the CreateChildControls method -
> and
> if so how do I fix this.
>
> Jim


Dec 20 '05 #5

P: n/a
I understand the problem. The reason the eventHandler is never executed, is
because the delete button no longer exists. The only way to make it exist
is to recreate it. To recreate it, you must simulate the
CommandEventHandler being clicked.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Jimmy Jazz" <Ji*******@discussions.microsoft.com> wrote in message
news:F4**********************************@microsof t.com...
Hi Karl,

No not quiet, The control loads on CreateChildControls the alphabet
buttons
are created with a ConnandEventHandler connected. Whan a user presses a
letter I use Viewstate to record the letter then show the terms and
buttons
next to them with a ConnandEventHandler connected. When a delete button is
pressed it posts back but does not go into the EventHandler where the
delete
functionality is held. Thas the problem

Jim
"Karl Seguin" wrote:
Not sure I understand.

There are a bunch of letters
User clicks one
There are a bunch of terms
User clicks one
Term is deleted
If you look at my example, every time a letter is clicked, that value is
stored in the viewstate. Your problem is that when a term is clicked,
the
letter isn't reloaded, hence the term isn't deleted. In my example, the
value from the viewstate is read during Page_Load and the page is
returned
to it's previous state.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Jimmy Jazz" <Ji*******@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
> Hi Karl,
> I cannot load up the terms, in the control I created the letter
> selected
> is
> not know until the
>
> AlphabetButton_Click(...)
>
> and all the controls have been written by then
>
> Jim
>
> "Karl Seguin" wrote:
>
>> Jim:
>> The entire state of the page needs to be created when a button is
>> clicked.
>> So when you press a delete button, you need to make sure that whatever
>> controls were loaded when a alphabet-button was clicked are loaded.
>>
>> My guess is that the delete button isn't re-created on postback, so
>> the
>> event never fires. A typical way to solve this is to store some info
>> in
>> the
>> viewstate. Here's some pseudocode:
>>
>> sub AlphabetButton_click(...)
>> LoadYourTerms(e.CommandArgument)
>> ViewState.Add("Letter", e.CommandArgument)
>> end sub
>>
>> sub page_load(...)
>> 'IF we are posting back AND there's a letter stored in the viewstate
>> if Page.IsPostBack AndAlso not ViewState("Letter") is nothing then
>> LoadYourTerms(ViewState("Letter"))
>> end if
>> end sub
>>
>>
>> Karl
>>
>> --
>> MY ASP.Net tutorials
>> http://www.openmymind.net/
>> http://openmymind.net/redirector.aspx?documentId=51 - Learn about
>> AJAX!
>>
>>
>>
>> "Jimmy Jazz" <Ji*******@discussions.microsoft.com> wrote in message
>> news:7C**********************************@microsof t.com...
>> > Hi,
>> >
>> > I have created a control with some buttons an alphabet. When one of
>> > these
>> > buttons are pressed it posts back and in the postback event for the
>> > button
>> > pressed a list of tems is created with a list of buttons next to
>> > them
>> > to
>> > delete the term. My problem is that the delete button has a delete
>> > event
>> > attached to it but t does not fire. Is this because the delete
>> > butons
>> > are
>> > created in the postbaclk event and not the CreateChildControls
>> > method -
>> > and
>> > if so how do I fix this.
>> >
>> > Jim
>>
>>
>>


Dec 20 '05 #6

P: n/a
Hi Karl,

Thanks for all your hel;p but how do you do that?

Jim

"Karl Seguin" wrote:
I understand the problem. The reason the eventHandler is never executed, is
because the delete button no longer exists. The only way to make it exist
is to recreate it. To recreate it, you must simulate the
CommandEventHandler being clicked.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Jimmy Jazz" <Ji*******@discussions.microsoft.com> wrote in message
news:F4**********************************@microsof t.com...
Hi Karl,

No not quiet, The control loads on CreateChildControls the alphabet
buttons
are created with a ConnandEventHandler connected. Whan a user presses a
letter I use Viewstate to record the letter then show the terms and
buttons
next to them with a ConnandEventHandler connected. When a delete button is
pressed it posts back but does not go into the EventHandler where the
delete
functionality is held. Thas the problem

Jim
"Karl Seguin" wrote:
Not sure I understand.

There are a bunch of letters
User clicks one
There are a bunch of terms
User clicks one
Term is deleted
If you look at my example, every time a letter is clicked, that value is
stored in the viewstate. Your problem is that when a term is clicked,
the
letter isn't reloaded, hence the term isn't deleted. In my example, the
value from the viewstate is read during Page_Load and the page is
returned
to it's previous state.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Jimmy Jazz" <Ji*******@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
> Hi Karl,
> I cannot load up the terms, in the control I created the letter
> selected
> is
> not know until the
>
> AlphabetButton_Click(...)
>
> and all the controls have been written by then
>
> Jim
>
> "Karl Seguin" wrote:
>
>> Jim:
>> The entire state of the page needs to be created when a button is
>> clicked.
>> So when you press a delete button, you need to make sure that whatever
>> controls were loaded when a alphabet-button was clicked are loaded.
>>
>> My guess is that the delete button isn't re-created on postback, so
>> the
>> event never fires. A typical way to solve this is to store some info
>> in
>> the
>> viewstate. Here's some pseudocode:
>>
>> sub AlphabetButton_click(...)
>> LoadYourTerms(e.CommandArgument)
>> ViewState.Add("Letter", e.CommandArgument)
>> end sub
>>
>> sub page_load(...)
>> 'IF we are posting back AND there's a letter stored in the viewstate
>> if Page.IsPostBack AndAlso not ViewState("Letter") is nothing then
>> LoadYourTerms(ViewState("Letter"))
>> end if
>> end sub
>>
>>
>> Karl
>>
>> --
>> MY ASP.Net tutorials
>> http://www.openmymind.net/
>> http://openmymind.net/redirector.aspx?documentId=51 - Learn about
>> AJAX!
>>
>>
>>
>> "Jimmy Jazz" <Ji*******@discussions.microsoft.com> wrote in message
>> news:7C**********************************@microsof t.com...
>> > Hi,
>> >
>> > I have created a control with some buttons an alphabet. When one of
>> > these
>> > buttons are pressed it posts back and in the postback event for the
>> > button
>> > pressed a list of tems is created with a list of buttons next to
>> > them
>> > to
>> > delete the term. My problem is that the delete button has a delete
>> > event
>> > attached to it but t does not fire. Is this because the delete
>> > butons
>> > are
>> > created in the postbaclk event and not the CreateChildControls
>> > method -
>> > and
>> > if so how do I fix this.
>> >
>> > Jim
>>
>>
>>


Dec 20 '05 #7

P: n/a
I still think my code is the right way to go.

As an alternative, you can look at Denis Bauer's free dynamic placeholder
control:
http://www.denisbauer.com/ASPNETCont...aceholder.aspx

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Jimmy Jazz" <Ji*******@discussions.microsoft.com> wrote in message
news:50**********************************@microsof t.com...
Hi Karl,

Thanks for all your hel;p but how do you do that?

Jim

"Karl Seguin" wrote:
I understand the problem. The reason the eventHandler is never executed,
is
because the delete button no longer exists. The only way to make it
exist
is to recreate it. To recreate it, you must simulate the
CommandEventHandler being clicked.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Jimmy Jazz" <Ji*******@discussions.microsoft.com> wrote in message
news:F4**********************************@microsof t.com...
> Hi Karl,
>
> No not quiet, The control loads on CreateChildControls the alphabet
> buttons
> are created with a ConnandEventHandler connected. Whan a user presses a
> letter I use Viewstate to record the letter then show the terms and
> buttons
> next to them with a ConnandEventHandler connected. When a delete button
> is
> pressed it posts back but does not go into the EventHandler where the
> delete
> functionality is held. Thas the problem
>
> Jim
> "Karl Seguin" wrote:
>
>> Not sure I understand.
>>
>> There are a bunch of letters
>> User clicks one
>> There are a bunch of terms
>> User clicks one
>> Term is deleted
>>
>>
>> If you look at my example, every time a letter is clicked, that value
>> is
>> stored in the viewstate. Your problem is that when a term is clicked,
>> the
>> letter isn't reloaded, hence the term isn't deleted. In my example,
>> the
>> value from the viewstate is read during Page_Load and the page is
>> returned
>> to it's previous state.
>>
>> Karl
>>
>> --
>> MY ASP.Net tutorials
>> http://www.openmymind.net/
>> http://openmymind.net/redirector.aspx?documentId=51 - Learn about
>> AJAX!
>>
>>
>>
>> "Jimmy Jazz" <Ji*******@discussions.microsoft.com> wrote in message
>> news:8A**********************************@microsof t.com...
>> > Hi Karl,
>> > I cannot load up the terms, in the control I created the letter
>> > selected
>> > is
>> > not know until the
>> >
>> > AlphabetButton_Click(...)
>> >
>> > and all the controls have been written by then
>> >
>> > Jim
>> >
>> > "Karl Seguin" wrote:
>> >
>> >> Jim:
>> >> The entire state of the page needs to be created when a button is
>> >> clicked.
>> >> So when you press a delete button, you need to make sure that
>> >> whatever
>> >> controls were loaded when a alphabet-button was clicked are loaded.
>> >>
>> >> My guess is that the delete button isn't re-created on postback, so
>> >> the
>> >> event never fires. A typical way to solve this is to store some
>> >> info
>> >> in
>> >> the
>> >> viewstate. Here's some pseudocode:
>> >>
>> >> sub AlphabetButton_click(...)
>> >> LoadYourTerms(e.CommandArgument)
>> >> ViewState.Add("Letter", e.CommandArgument)
>> >> end sub
>> >>
>> >> sub page_load(...)
>> >> 'IF we are posting back AND there's a letter stored in the
>> >> viewstate
>> >> if Page.IsPostBack AndAlso not ViewState("Letter") is nothing
>> >> then
>> >> LoadYourTerms(ViewState("Letter"))
>> >> end if
>> >> end sub
>> >>
>> >>
>> >> Karl
>> >>
>> >> --
>> >> MY ASP.Net tutorials
>> >> http://www.openmymind.net/
>> >> http://openmymind.net/redirector.aspx?documentId=51 - Learn about
>> >> AJAX!
>> >>
>> >>
>> >>
>> >> "Jimmy Jazz" <Ji*******@discussions.microsoft.com> wrote in message
>> >> news:7C**********************************@microsof t.com...
>> >> > Hi,
>> >> >
>> >> > I have created a control with some buttons an alphabet. When one
>> >> > of
>> >> > these
>> >> > buttons are pressed it posts back and in the postback event for
>> >> > the
>> >> > button
>> >> > pressed a list of tems is created with a list of buttons next to
>> >> > them
>> >> > to
>> >> > delete the term. My problem is that the delete button has a
>> >> > delete
>> >> > event
>> >> > attached to it but t does not fire. Is this because the delete
>> >> > butons
>> >> > are
>> >> > created in the postbaclk event and not the CreateChildControls
>> >> > method -
>> >> > and
>> >> > if so how do I fix this.
>> >> >
>> >> > Jim
>> >>
>> >>
>> >>
>>
>>
>>


Dec 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.