Button events

G

Guest

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
 
K

Karl Seguin

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
 
G

Guest

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
 
K

Karl Seguin

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
 
G

Guest

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
 
K

Karl Seguin

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,538
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top