|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
AddHandler doesn't seem to work.I am creating an ImageButton at run time and adding it to a place holder
control's collection. I am using the AddHandler to associate a procedure with the Command event but when I click on the ImageButton at runtime, it doesn't fire the procedure... Here is my code: ' Add Image Button ibnConfirm = New ImageButton ibnConfirm.ImageUrl = "Confirm16.ico" ibnConfirm.CommandName = "Confirm" ibnConfirm.CommandArgument = e.Item.DataItem("pk_Quotation_in") ibnConfirm.ToolTip = "Confirm Quotation" AddHandler ibnConfirm.Command, AddressOf ibnConfirm_Command ' Add to place holder collection plhConfirm.Controls.Add(ibnConfirm) And you add the ImageButton similarly on postback as well?
-- Teemu Keiski ASP.NET MVP, AspInsider Finland, EU My control is being added in the ItemDataBound event of a Repeater control
(It may be added once per row of data). So presumably, that is ok? Hi,
if adding in ItemdataBound indeed means instantiating there and adding to the Row's Controls, that's the reason why it wouldn't work because it isn't there by the time when postback happens (until rebinding the grid). ImageButton here is a dynamical control and it needs to be added to the Controls collection on every request( for the time it is needed) for everything to work smoothly. Events won't be raised on postback if the control is not there. So that the control would exist there as is needed for postback data handling, it would need to be instantiated also in ItemCreated. You probably detect from data that should the control be created which makes it harder to manage, because you really *need* also to instantiate the control in ItemCreated but the info comes from ItemdataBound So you could check in ItemDataBound if data indicates a control needs to be created (on databinding ItemCreated is first called and then ItemDataBound, on postback when not binding only ItemCreated is called --> causes the basic problem with dynamical controls) . You'd need to store on row-basis (say to ViewState) if the control needs to recreated on following requests and then based on this info cause also instation in ItemCreated. So idea : 1. In ItemDataBound check the data, should the control be created and if it should create it there. Set a row-level flag (to viewstate) that the control is created 2. In ItemCreated check the existence of this flag and based on it, recreate the control as needed I also have a few pointers for you, the same thing is discussed here http://forums.asp.net/674362/ShowPost.aspx http://forums.asp.net/745711/ShowPost.aspx And there's also a free control that might be able to help you. http://forums.asp.net/745711/ShowPost.aspx -- Teemu Keiski ASP.NET MVP, AspInsider Finland, EU
SRE (Simple Rule Engine)
ImageButton bug Help, DropDown Web Control not Retuning "SelectedValue" Blinking Controls Drop down listbox - extra properties, possible? CUSTOMVALIDATOR works but page goes on on FALSE "Google Suggests" and the AJAX .NET Wrapper? CustomValidator VALIDA pero NO FUNCIONA REGEX para Email I want to do a process once per page process, but 'touch' all instances of my server control. |
|||||||||||||||||||||||