Wednesday, March 28, 2012

Link Button as trigger not firing

So I have a link button that is created here...

 LinkButton hide =new LinkButton(); hide.Text ="(hide)"; hide.Click +=new EventHandler(this.hide_Click); hide.ID ="hide" + deviceID;

which is later added to a table cell which is added to a table row which is added to a table. This table is what my function returns (the functions basically builds the table)

From where the function is called I have this code to create a trigger using the linkbutton hide, then add that trigger to the update panel that i am putting the newley created table in...

 AsyncPostBackTrigger trig =new AsyncPostBackTrigger(); ((UpdatePanel)tempTable.Parent.Parent).ContentTemplateContainer.Controls.Add(childTable); trig.ControlID = childTable.Rows[0].Cells[1].Controls[1].UniqueID; trig.EventName ="Click"; ((UpdatePanel)childTable.Parent.Parent).Triggers.Add(trig);

I have tried making the controlID both the unique ID and just the ID and neither work. I know that my just for testing my hide_click function is simple...

private void hide_Click(object sender, EventArgs e) { txtOutput.Text ="IT WORKED!"; }

I know the hide_Click function works because i attached it to other buttons in other tables and it executes fine.

Does anyone know if I am doing something wrong because I cannot seem to figure this out.

Thanks

Hi,

what issue are you experiencing? A full postback instead of an async postback? Or the "IT WORKED!" text isn't displayed? In this case, did you put the Label inside an UpdatePanel?


There is no postback at all. The txtOuput is inside an update panel. It works fine when triggered from other buttons that were added to my page the same way I am adding my link button, but something is acting up. Im not sure if there is a problem with where I am adding the trigger so I am going to try defining the trigger at the same place in code as where I am defining the link button to see if that helps, but i doubt that will change anything.


Ok this is really starting to mess with my head. I have noticed now that when i click on my button, the textbox txtOutput refreshes, but still displays the text that was already there, instead of getting the text from the hide_Click function. This is weird though because when I point other buttons to my hide_Click function, they fire it perfectly and the text box updates. I am confussed


Hi,

Please refer to this:

http://ajax.asp.net/docs/mref/T_System_Web_UI_AsyncPostBackTrigger.aspx

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.

Please try as the above documentation described. If still fails, please post a self-sufficient repro.


great thanks, ill take a look. I was all excited because I was able to programatically add asyncpostback trigers to some update panels, I did this at the time the panels were being created and it worked fine, I guess there are some situations where it just doesnt work though.


so it turns out the trigger is working fine, the only problem is that my hide_Click event isnt being fired. I have had this problem before where having certain settings enabled for different controls cause the controls .click event not to work properly, now its just a matter of finding out what is causing this problem

No comments:

Post a Comment