But whatever I do, it doesn't seem to call the handler. I tried a lot of things such as registering a postback trigger (Asynch & Synch) from the updatePanel or the ScriptManager, changing the update mode to conditional or always, checking the xhtmlConformance
property in the web.config file,...
Nothing seems to work and I'm pretty sure it doesn't execute the handler because whatever I do inside nothing happens.
I'm starting to be desperate so if you guys have any idea ?
Programmatically adding AsyncPostBackTrigger controls is not supported. Use the
RegisterAsyncPostBackControl(Control) method of the
ScriptManager control to programmatically register a postback control, and then call the
Update() method of the
UpdatePanel when the control posts back.
Chetan Sarode
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
I have a similar problem, but with regard to a LinkButton that I'm adding in a panel with the following hierarchy:
Page --> UpdatePanel --> UserControl --> Panel
The LinkButtons are getting dynamically created and added to an HtmlTable construct inside the Panel (since I couldn't seem to get a ListView control to do what I wanted) in response to a method invoked by a button:
Button is clicked (table does not exist yet)
Search is performed, and a "GenerateResultsView" method is called
Table is constructed with Rows, Cells, etc.
LinkButton is added to each cell.
Here's the code for the adding of the button:
// create the "search by ID" link button
LinkButton searchByIdLinkButton = new LinkButton();
searchByIdLinkButton.ID = "searchByIdLinkButton_" + itemsAdded.ToString();
searchByIdLinkButton.CommandName = "SearchById";
searchByIdLinkButton.CommandArgument = doc.ImageID;
searchByIdLinkButton.Command += new CommandEventHandler(HandleSearchByIdLinkCommand);
searchByIdLinkButton.CausesValidation = false;
searchByIdLinkButton.OnClientClick = "SearchBuilder.prepareSearchById('searchByIdHidden');";
searchByIdLinkButton.Text = "Find More Like This";
On the surface, the table gets generated perfectly, with the LinkButtons. But, of course when the link is clicked, the
HandleSearchByIdLinkCommand event does not get called.
So I've read some folks suggest to put this type of LinkButton-building-code in the Page_Init, but I'm not quite sure how to do that given the way I'm generating the Table and the LinkButtons.
Others suggest, as above, to use RegisterAsyncPostBackControl, which I tried from but it didn't seem to work either, but perhaps that was because I was trying to hook them up in the same method where I was building the table and controls.
Also the "static array of controls" suggestion sounds dicey to me since wouldn't that expose the array to
all the users?
Anyway I was just looking for a relatively simple way to fix this.
Worst case scenario, I can just turn the LinkButtons into Hyperlinks or HtmlAnchors, but the Command model is just
so convenient and intuitive for this kind of thing. I'd really prefer to get it working that way if possible...
Thanks!
evan k. stone | sr. .NET web developer | sf bay area, ca | twitter: interactivlogic (no "e." twitter only allows 15 chars.)
I guess I should mention that clicking the LinkButton is doing *something* - I'm just not quite sure what, and it's certainly not good.
Additionally when it's "done" the page is pretty well disabled. the main submit button i'm using no longer trigger partial postbacks so the page is in this strange limbo state.
Very odd.
evan k. stone | sr. .NET web developer | sf bay area, ca | twitter: interactivlogic (no "e." twitter only allows 15 chars.)
...I guess what I'm trying to figure out is why the ListView control can generate these links dynamically without any problems (I think it's a conspiracy ;) ).
The "ListView version" of the search results I'm generating works great, but doesn't look right because I need to put the results in
two rows not one (because of alternating sizes of the images of the items I'm returning), and therefore looks like crap. My generated table looks better, but the LinkButtons don't send their commands.
Maybe I'd better explore different ways of laying out the ListView version to see if I can get something more acceptable.
evan k. stone | sr. .NET web developer | sf bay area, ca | twitter: interactivlogic (no "e." twitter only allows 15 chars.)
OK... I figured I'd better write back to describe my elaborate workaround
to circumvent this lameness:
Instead of creating a LinkButton, I dynamcially create a Hyperlink object in my search result items.
Using a similar technique to the one outlined by JazzMan6180in
this forum post, I add an attribute to the hyperlink containing a piece of information which I will later read to perform a subsequent search: let's call it "SearchId" (this probably would not be necessary since I could have embedded it
in the URL, but I just felt that the attribute is more appropriate for what I'm doing, and less hacky).
I wire up the hyperlink's [client-side] javascript onclick event (via Attributes, again) to call to a javascript function which will invoke the search.
Created a hidden input field to hold the value contained in "SearchId" attribute of the clicked link. The aforementioned javascript function takes the ID from the SearchID attribute and pops it into the hidden field and also sets a value in another hidden
field that indicates that this type of search is occuring.
Manually initiate a postback, pretending that it was a search button that invoked it.
Server side: Handle the postback event as if the button triggered it, and check to see if this is the link-clicked-search or the button-clicked-search by inspecting the second hidden field.
Call the method that handles the link-invoked-search.
Do the search, populate results.
Rinse, lather repeat.
I find it rather sad that I had to go through all this when dynamically adding the linkbutton controls and having them get wired up properly
should have just worked.
At any rate, if any other poor souls have tread down this path and wonder what to do, this may offer
some help, albeit very heavy-handed and unnecessarily workaround-ish.
P.S. Anyone notice the "Tags" feature beneath the editor (including the "Select Tags" dialog) is just totally a freak of nature and is a totally
inexcusablypoor user experience?
evan k. stone | sr. .NET web developer | sf bay area, ca | twitter: interactivlogic (no "e." twitter only allows 15 chars.)
B4xt3r
0 Points
1 Post
Button command not working inside an UpdatePanel
Aug 31, 2009 07:15 PM|LINK
Hello,
I'm having a problem with a Button inside an UpdatePanel, I've been trying a lot of things and still nothing is working.
Here is my problem:
I update the UpdatePanel from a LinkButton:
LinkButton lnkImg = new LinkButton();
lnkImg.ID = "lnk_"+i.ToString();
lnkImg.CommandArgument = i.ToString();
lnkImg.Command += new CommandEventHandler(displayImageProperties);
AsyncPostBackTrigger triggerImage = new AsyncPostBackTrigger();
triggerImage.ControlID = lnkImg.ID;
triggerImage.EventName = "Click";
UpdatePanelProperties.Triggers.Add(triggerImage);
I add a button to my UpdatePanel from the displayImageProperties event handler
void displayImageProperties(object sender, CommandEventArgs e)
{
...
Button btnAddTitle = new Button();
btnAddTitle.ID = "btnAddTitle";
btnAddTitle.Text = "Add";
btnAddTitle.CommandArgument = indexFile.ToString();
btnAddTitle.Command += new CommandEventHandler(addTitle);
UpdatePanelProperties.ContentTemplateContainer.Controls.Add(btnAddTitle);
...
}
The button is added to the list of controls of the ContentTemplateContainer
Here is my handler (addTitle):
void addTitle(object sender, CommandEventArgs e) { }
But whatever I do, it doesn't seem to call the handler. I tried a lot of things such as registering a postback trigger (Asynch & Synch) from the updatePanel or the ScriptManager, changing the update mode to conditional or always, checking the xhtmlConformance property in the web.config file,...
Nothing seems to work and I'm pretty sure it doesn't execute the handler because whatever I do inside nothing happens.
I'm starting to be desperate so if you guys have any idea ?
Thank you !
Ambran
Contributor
3183 Points
612 Posts
Re: Button command not working inside an UpdatePanel
Aug 31, 2009 07:44 PM|LINK
Hi
Found this thread which should help you:
http://forums.asp.net/p/1461931/3362080.aspx#3362352
Amit
chetan.sarode
All-Star
53419 Points
9044 Posts
Re: Button command not working inside an UpdatePanel
Sep 03, 2009 10:46 AM|LINK
Programmatically adding AsyncPostBackTrigger controls is not supported. Use the RegisterAsyncPostBackControl(Control) method of the ScriptManager control to programmatically register a postback control, and then call the Update() method of the UpdatePanel when the control posts back.
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
evankstone
Member
54 Points
36 Posts
Re: Button command not working inside an UpdatePanel
Nov 23, 2009 07:57 PM|LINK
I have a similar problem, but with regard to a LinkButton that I'm adding in a panel with the following hierarchy:
Page --> UpdatePanel --> UserControl --> Panel
The LinkButtons are getting dynamically created and added to an HtmlTable construct inside the Panel (since I couldn't seem to get a ListView control to do what I wanted) in response to a method invoked by a button:
Here's the code for the adding of the button:
// create the "search by ID" link button LinkButton searchByIdLinkButton = new LinkButton(); searchByIdLinkButton.ID = "searchByIdLinkButton_" + itemsAdded.ToString(); searchByIdLinkButton.CommandName = "SearchById"; searchByIdLinkButton.CommandArgument = doc.ImageID; searchByIdLinkButton.Command += new CommandEventHandler(HandleSearchByIdLinkCommand); searchByIdLinkButton.CausesValidation = false; searchByIdLinkButton.OnClientClick = "SearchBuilder.prepareSearchById('searchByIdHidden');"; searchByIdLinkButton.Text = "Find More Like This";On the surface, the table gets generated perfectly, with the LinkButtons. But, of course when the link is clicked, the HandleSearchByIdLinkCommand event does not get called.
So I've read some folks suggest to put this type of LinkButton-building-code in the Page_Init, but I'm not quite sure how to do that given the way I'm generating the Table and the LinkButtons.
Others suggest, as above, to use RegisterAsyncPostBackControl, which I tried from but it didn't seem to work either, but perhaps that was because I was trying to hook them up in the same method where I was building the table and controls.
Also the "static array of controls" suggestion sounds dicey to me since wouldn't that expose the array to all the users?
Anyway I was just looking for a relatively simple way to fix this.
Worst case scenario, I can just turn the LinkButtons into Hyperlinks or HtmlAnchors, but the Command model is just so convenient and intuitive for this kind of thing. I'd really prefer to get it working that way if possible...
Thanks!
evankstone
Member
54 Points
36 Posts
Re: Button command not working inside an UpdatePanel
Nov 23, 2009 10:49 PM|LINK
I guess I should mention that clicking the LinkButton is doing *something* - I'm just not quite sure what, and it's certainly not good.
Additionally when it's "done" the page is pretty well disabled. the main submit button i'm using no longer trigger partial postbacks so the page is in this strange limbo state.
Very odd.
evankstone
Member
54 Points
36 Posts
Re: Button command not working inside an UpdatePanel
Nov 24, 2009 04:51 PM|LINK
...I guess what I'm trying to figure out is why the ListView control can generate these links dynamically without any problems (I think it's a conspiracy ;) ).
The "ListView version" of the search results I'm generating works great, but doesn't look right because I need to put the results in two rows not one (because of alternating sizes of the images of the items I'm returning), and therefore looks like crap. My generated table looks better, but the LinkButtons don't send their commands.
Maybe I'd better explore different ways of laying out the ListView version to see if I can get something more acceptable.
evankstone
Member
54 Points
36 Posts
Re: Button command not working inside an UpdatePanel
Nov 24, 2009 08:56 PM|LINK
OK... I figured I'd better write back to describe my elaborate workaround to circumvent this lameness:
I find it rather sad that I had to go through all this when dynamically adding the linkbutton controls and having them get wired up properly should have just worked.
At any rate, if any other poor souls have tread down this path and wonder what to do, this may offer some help, albeit very heavy-handed and unnecessarily workaround-ish.
P.S. Anyone notice the "Tags" feature beneath the editor (including the "Select Tags" dialog) is just totally a freak of nature and is a totally inexcusably poor user experience?