Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Problem handling event in a button inside a Datalist

Reply
Thread Tools

Problem handling event in a button inside a Datalist

 
 
ed
Guest
Posts: n/a
 
      07-11-2006
Hello All.

Scenario: I have a web form with a textbox, a button and a datalist (lets
call it datalist1), when the user clicks in the button I add items to the
datalist1 as much as the textbox says. Each item in datalist1 has a label, a
link button and other datalist (datalist2), the label shows the item index,
and above the datalist2 I have a link button intended to add items to the
datalist2. I successfully can add items to the datalist1 when clicking the
button, but when clicking the Add linkbutton nothing happens. I subscribed
the onclick event by getting a reference to the button in the ItemDataBound
event in datalist1.

private void datalist1_ItemDataBound(object sender, DataListItemEventArgs e)
{
LinkButton lnkAdd = (LinkButton)e.Item.FindControl("lnkAdd ");
lnkAdd.Click += new EventHandler(lnk_Click);
}

private void lnkAdd _Click(object sender, EventArgs e)
{
// This never executes…
}

Is this way right to subscribe the event to the "add" button? What can be
the cause of this?

Thank you very much

 
Reply With Quote
 
 
 
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      07-12-2006
hi Ed, you can respond to the event in ItemCommand event exposed by the
datalist. All child controls that fire events bubbleup and fired here.

http://msdn2.microsoft.com/en-us/library/y200hyx2.aspx

Or you can keep your current code and instead of wiring the event in
ItemDataBound you can wire it declaratively in your linkbutton itself
<asp:linkButton .... onclick="lnkAdd" />

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net

"ed" <(E-Mail Removed)> ha scritto nel messaggio
news(E-Mail Removed)...
> Hello All.
>
> Scenario: I have a web form with a textbox, a button and a datalist (lets
> call it datalist1), when the user clicks in the button I add items to the
> datalist1 as much as the textbox says. Each item in datalist1 has a
> label, a
> link button and other datalist (datalist2), the label shows the item
> index,
> and above the datalist2 I have a link button intended to add items to the
> datalist2. I successfully can add items to the datalist1 when clicking the
> button, but when clicking the Add linkbutton nothing happens. I subscribed
> the onclick event by getting a reference to the button in the
> ItemDataBound
> event in datalist1.
>
> private void datalist1_ItemDataBound(object sender, DataListItemEventArgs
> e)
> {
> LinkButton lnkAdd = (LinkButton)e.Item.FindControl("lnkAdd ");
> lnkAdd.Click += new EventHandler(lnk_Click);
> }
>
> private void lnkAdd _Click(object sender, EventArgs e)
> {
> // This never executes.
> }
>
> Is this way right to subscribe the event to the "add" button? What can be
> the cause of this?
>
> Thank you very much
>



 
Reply With Quote
 
 
 
 
ed
Guest
Posts: n/a
 
      07-12-2006
Thank you very much

It worked this way: <asp:linkButton .... onclick="lnkAdd" />

"Alessandro Zifiglio" wrote:

> hi Ed, you can respond to the event in ItemCommand event exposed by the
> datalist. All child controls that fire events bubbleup and fired here.
>
> http://msdn2.microsoft.com/en-us/library/y200hyx2.aspx
>
> Or you can keep your current code and instead of wiring the event in
> ItemDataBound you can wire it declaratively in your linkbutton itself
> <asp:linkButton .... onclick="lnkAdd" />
>
> Regards,
> Alessandro Zifiglio
> http://www.AsyncUI.net
>
> "ed" <(E-Mail Removed)> ha scritto nel messaggio
> news(E-Mail Removed)...
> > Hello All.
> >
> > Scenario: I have a web form with a textbox, a button and a datalist (lets
> > call it datalist1), when the user clicks in the button I add items to the
> > datalist1 as much as the textbox says. Each item in datalist1 has a
> > label, a
> > link button and other datalist (datalist2), the label shows the item
> > index,
> > and above the datalist2 I have a link button intended to add items to the
> > datalist2. I successfully can add items to the datalist1 when clicking the
> > button, but when clicking the Add linkbutton nothing happens. I subscribed
> > the onclick event by getting a reference to the button in the
> > ItemDataBound
> > event in datalist1.
> >
> > private void datalist1_ItemDataBound(object sender, DataListItemEventArgs
> > e)
> > {
> > LinkButton lnkAdd = (LinkButton)e.Item.FindControl("lnkAdd ");
> > lnkAdd.Click += new EventHandler(lnk_Click);
> > }
> >
> > private void lnkAdd _Click(object sender, EventArgs e)
> > {
> > // This never executes.
> > }
> >
> > Is this way right to subscribe the event to the "add" button? What can be
> > the cause of this?
> >
> > Thank you very much
> >

>
>
>

 
Reply With Quote
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      07-13-2006
you are welcome, ed

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net


"ed" <(E-Mail Removed)> ha scritto nel messaggio
news:(E-Mail Removed)...
> Thank you very much
>
> It worked this way: <asp:linkButton .... onclick="lnkAdd" />
>
> "Alessandro Zifiglio" wrote:
>
>> hi Ed, you can respond to the event in ItemCommand event exposed by the
>> datalist. All child controls that fire events bubbleup and fired here.
>>
>> http://msdn2.microsoft.com/en-us/library/y200hyx2.aspx
>>
>> Or you can keep your current code and instead of wiring the event in
>> ItemDataBound you can wire it declaratively in your linkbutton itself
>> <asp:linkButton .... onclick="lnkAdd" />
>>
>> Regards,
>> Alessandro Zifiglio
>> http://www.AsyncUI.net
>>
>> "ed" <(E-Mail Removed)> ha scritto nel messaggio
>> news(E-Mail Removed)...
>> > Hello All.
>> >
>> > Scenario: I have a web form with a textbox, a button and a datalist
>> > (lets
>> > call it datalist1), when the user clicks in the button I add items to
>> > the
>> > datalist1 as much as the textbox says. Each item in datalist1 has a
>> > label, a
>> > link button and other datalist (datalist2), the label shows the item
>> > index,
>> > and above the datalist2 I have a link button intended to add items to
>> > the
>> > datalist2. I successfully can add items to the datalist1 when clicking
>> > the
>> > button, but when clicking the Add linkbutton nothing happens. I
>> > subscribed
>> > the onclick event by getting a reference to the button in the
>> > ItemDataBound
>> > event in datalist1.
>> >
>> > private void datalist1_ItemDataBound(object sender,
>> > DataListItemEventArgs
>> > e)
>> > {
>> > LinkButton lnkAdd = (LinkButton)e.Item.FindControl("lnkAdd ");
>> > lnkAdd.Click += new EventHandler(lnk_Click);
>> > }
>> >
>> > private void lnkAdd _Click(object sender, EventArgs e)
>> > {
>> > // This never executes.
>> > }
>> >
>> > Is this way right to subscribe the event to the "add" button? What can
>> > be
>> > the cause of this?
>> >
>> > Thank you very much
>> >

>>
>>
>>



 
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
Databound inside DataList with another DataList Steve ASP .Net 0 02-01-2005 04:39 PM
handling radio button event in user controls datalist manu_srinivasa ASP .Net 0 11-24-2004 09:57 AM
Setting up a datalist control - Item_DataBound for a datalist in a datalist Nevyn Twyll ASP .Net 8 09-09-2004 10:13 PM
Image Button inside a template column - Handling The Click Event KJ ASP .Net Web Controls 3 08-08-2003 05:19 PM



Advertisments