Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Wire up a click event within another click event doesn't work...

Reply
Thread Tools

Wire up a click event within another click event doesn't work...

 
 
Chu
Guest
Posts: n/a
 
      04-10-2006
Thanks everyone for taking a moment to read this.

I've got a page where I use a LinkButton and I wire up a dynamic event
to the button. When the user clicks the button, the event is fired as
expected. In the event code for that button, a new LinkButton is added
to the page and is wired up to yet a different event, however when
clicked, the page is posted back but the event is not triggered.

I'm assuming it has something to do with the order of events that are
being fired (i.e, it appears page_load gets hit then the first
LinkButton's click event is fired) and so the wire up isn't working out
as expected.

My problem is that I have no idea where to go from here Is it even
possible to do what I'm wanting, i.e, wire up a 2nd button on the same
page that the 1st button was pushed?

Thanks for any help.

 
Reply With Quote
 
 
 
 
Karl Seguin [MVP]
Guest
Posts: n/a
 
      04-10-2006
It isn't an easy problem to solve.

Basically, for an event to fire, it needs to be hooked up on postback during
or before page_load.

you already have 2 problems.

(a) you aren't hooking it up during postback (well, you are during 1
postback, but not the 2nd one which is the important one)
(b) even if you were, it'd be too late

this is what you are doing:

Button 1 clicked
Page_Load
Setup event for button1 (you might be doing this somewhere else, you
didn't specify
end load
LoadPostback
Create 2nd button
Setup eventhandler for button2
end loadPostback

Button2 Clicked
Page_Load
Nothing's happening
end load
No events to raise


What needs to happen in Button2 click is:
Page_Load
Recreate button2
Hook up the event
end load
Here your event will fire.


As I said, it isn't fun to solve. If your pages don't need viewstate, I'd
personally use straight links and pass vlaues in the querystring <a
href="samepage.aspx?action=button2">blah</a>

If viewstate is important, you need to do somethin glike:

Button1 click:
create2nd button
ViewState.Add("Load2ndButton", true);
end click

Postback:
Page_Load
IF Page.IsPostBack then
If ViewState["Load2ndButton"] = true then
Load button 2
Setup event handler
end if
end if
End page load


all pseudo code of course...hopefully that gives you some ideas..

Karl

--
http://www.openmymind.net/



"Chu" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Thanks everyone for taking a moment to read this.
>
> I've got a page where I use a LinkButton and I wire up a dynamic event
> to the button. When the user clicks the button, the event is fired as
> expected. In the event code for that button, a new LinkButton is added
> to the page and is wired up to yet a different event, however when
> clicked, the page is posted back but the event is not triggered.
>
> I'm assuming it has something to do with the order of events that are
> being fired (i.e, it appears page_load gets hit then the first
> LinkButton's click event is fired) and so the wire up isn't working out
> as expected.
>
> My problem is that I have no idea where to go from here Is it even
> possible to do what I'm wanting, i.e, wire up a 2nd button on the same
> page that the 1st button was pushed?
>
> Thanks for any help.
>



 
Reply With Quote
 
 
 
 
Winista
Guest
Posts: n/a
 
      04-10-2006
Its the dynamically added link button that is causing the problem for you.
By the time page_load finishes the control hierarchy should be recreated so
that the events can be wired properly to the control that caused it. Since
you are not adding that link button in Page_Load or before, that event is
lost.
What you may have to do is, look at __EVENTTARGET value in FORM's collection
in page_load to check if the event was caused by your dynamically added
control and then do your stuff.

http://www.netomatix.com

"Chu" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Thanks everyone for taking a moment to read this.
>
> I've got a page where I use a LinkButton and I wire up a dynamic event
> to the button. When the user clicks the button, the event is fired as
> expected. In the event code for that button, a new LinkButton is added
> to the page and is wired up to yet a different event, however when
> clicked, the page is posted back but the event is not triggered.
>
> I'm assuming it has something to do with the order of events that are
> being fired (i.e, it appears page_load gets hit then the first
> LinkButton's click event is fired) and so the wire up isn't working out
> as expected.
>
> My problem is that I have no idea where to go from here Is it even
> possible to do what I'm wanting, i.e, wire up a 2nd button on the same
> page that the 1st button was pushed?
>
> Thanks for any help.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to wire click event with argument when create input quoclinh Javascript 4 06-26-2007 09:11 PM
DMA 40-pin/80-Wire with a empty spot on one wire? lcs A+ Certification 1 02-02-2006 09:06 AM
2 Wire and 3 Wire Telecom Wiring SchoolTech NZ Computing 1 02-26-2005 08:23 AM
How to wire a button click event in a composite control? Russ ASP .Net Web Controls 2 07-22-2004 03:50 PM
wire enter to button click Derrick ASP .Net 3 07-02-2004 03:40 PM



Advertisments