|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Problem handling event in a button inside a DatalistScenario: 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 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 Show quoteHide quote "ed" <e*@discussions.microsoft.com> ha scritto nel messaggio news:D57BA7D8-C78B-485B-AB03-CBB3FA67B671@microsoft.com... > 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 > Thank you very much :)
It worked this way: <asp:linkButton .... onclick="lnkAdd" /> Show quoteHide quote "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*@discussions.microsoft.com> ha scritto nel messaggio > news:D57BA7D8-C78B-485B-AB03-CBB3FA67B671@microsoft.com... > > 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 > > > > > you are welcome, ed :-)
Regards, Alessandro Zifiglio http://www.AsyncUI.net Show quoteHide quote "ed" <e*@discussions.microsoft.com> ha scritto nel messaggio news:0812310B-B188-48A0-899C-A444150D578A@microsoft.com... > 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*@discussions.microsoft.com> ha scritto nel messaggio >> news:D57BA7D8-C78B-485B-AB03-CBB3FA67B671@microsoft.com... >> > 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 >> > >> >> >>
Repeater and text boxes inside
how to change labelvalue when deleting row in gridview? How to put an image in a GridView Can't install iewebcontrols.msi - error "webctrl_client is unavailable" passing variable to sql statement in asp.net 2.0? textfield not recognized in gridview menu control with XML file creative scroll bar for asp.net Datagrids and User Controls Menu control and hover text color |
|||||||||||||||||||||||