I use Asp.net Ajax exten1.0 encounter some question,so I need your help
My problem is :
I use two UpdatePanel in one aspx ,we can call left panel ,and right panel
At right panel ,I need to automatism make a server table ,and in every table cell ,I must bind a linkbutton in there , as linkbutton , the linkbutton text data is from database, linkbutton bind it ,and linkbutoon commandArgument are bind data also ,
now , I encounter problem is , when I click linkbutton , but not trigger linkButton _command this Event ,so I cannot get commandArgument value.to diplay at updatepanel1 ,but ,I assurance I register this Event , when the linkbutton automatism make ,sure I use this method
eg:
lnkButton =New LinkButton() ' add EventAddHandler lnkButton.Command,AddressOf lnkButton_Command
eg : add trigger
Dim trigger As AsyncPostBackTrigger = New AsyncPostBackTrigger() trigger.ControlID = lnkButton.ID UpdatePanel2.Triggers.Add(trigger) I Add tirggers but , in html source I cannot find like these code , Sys.WebForms.PageRequestManager._initialize('ScriptManager1', document.getElementById('form1'));Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tUpdatePanel1','tUpdatePanel2'], ['btnConfrim','CalendarSelect','k0_0_0_0','k0_0_0_1','k0_0_0_2','k0_0_0_3','k0_0_1_0','k0_0_1_1','k0_0_1_2','k0_0_1_3','k0_0_2_0','k0_0_2_1','k0_0_2_2','k0_0_2_3','k0_0_3_0','k0_0_3_1','k0_0_3_2','k0_0_3_3','k0_1_0_0','k0_1_0_1','k0_1_0_2','k0_1_0_3','k0_1_1_0','k0_1_1_1','k0_1_1_2','k0_1_1_3','k0_1_2_0','k0_1_2_1','k0_1_2_2','k0_1_2_3','k0_1_3_0','k0_1_3_1','k0_1_3_2','k0_1_3_3','k0_2_0_0','k0_2_0_1','k0_2_0_2','k0_2_0_3','k0_2_1_0','k0_2_1_1','k0_2_1_2','k0_2_1_3','k0_2_2_0','k0_2_2_1','k0_2_2_2','k0_2_2_3',This 'k0_2_0_3' is linkbutton ID , That is why , thank you for your help
Your English is a bit shaky, so it was difficult to decipher exactly what is going on. However, one thing for sure that you are doing wrong is that you cannot create triggers programmatically. That is stated in the UpdatePanel Class page. If you simply use the ChildrenAsTriggers property set to true which is default, then when a link is clicked it will trigger the UpdatePanel update. However the issue of the command argument not available can be a bit more complex. It depends on the order of events and that is too complex to anayze without a simplified version of your code posted here. (Use the code editor button above to paste it a bit more neatly).
An example of why this might be necessary is that the order of page events can be affected by what is done during the page life cycle. For example I have seen the order of 2 events reverse simply by doing a FindControl or not in a method. There are muliple points in the life cycle where a control can Bind for instance and it may in fact Bind multiple times without you knowing it. That's just the way it works.
I would suggest that you add a Trace to all relevant events and check the order of events as that can sometimes give you insight. I have a very complex GridView run in Ajax, and without Trace events, I never would have been able to figure out what was wrong during edit with 2 way binding templates, column re-ordering, multi-column sorting, paging, etc all of which occur with Ajax.
sorry , my english is very poor.
my code is :
Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.Load createTable()End Sub'Public Sub createTable()For iAs Integer = 0To 5Dim rowAs TableRow =New TableRow()For jAs Integer = 0To 6Dim cellAs TableCell =New TableCell() cell.Controls.Add(CreatePerSolt(i, j)) row.Controls.Add(cell)Next tabShecule.Controls.Add(row)Next End Sub Public Function CreatePerSolt(ByVal iAs Integer,ByVal jAs Integer)As TableDim tabAs Table =New Table tab.ID = i &"_" &"_" & jFor kAs Integer = 0To 3Dim rowAs TableRow =New TableRow()For hAs Integer = 0To 3Dim cellAs TableCell =New TableCell() lnkButton =New LinkButton() lnkButton.Text ="k" & i &"_" & j &"_" & k &"_" & h lnkButton.ID ="k" & i &"_" & j &"_" & k &"_" & h lnkButton.CommandArgument ="k" & i &"_" & j &"_" & k &"_" & hAddHandler lnkButton.Command,AddressOf lnkButton_CommandDim triggerAs AsyncPostBackTrigger =New AsyncPostBackTrigger() trigger.ControlID = lnkButton.ID trigger.EventName ="Click" UpdatePanel2.Triggers.Add(trigger) cell.Controls.Add(lnkButton) row.Controls.Add(cell)Next tab.Controls.Add(row)Next Return tabEnd Function Protected Sub lnkButton_Command(ByVal senderAs Object,ByVal eAs System.Web.UI.WebControls.CommandEventArgs)Handles lnkButton.Command Label18.Text = e.CommandArgument.ToString()End Sub
I think you have to try this a different way to start.
http://www.asp.net/AJAX/Documentation/Live/mref/T_System_Web_UI_UpdatePanel.aspx
Please note the following statement:
You can add anUpdatePanel control programmatically, but you cannot add triggers programmatically. To create trigger-like behavior, you can register a control on the page as an asynchronous postback control. You do this by calling theRegisterAsyncPostBackControl(Control) method of theScriptManager control. You can then create an event handler that runs in response to the asynchronous postback, and in the handler, call theUpdate() method of theUpdatePanel control.
However because your table is inside the UpdatePanel, if you have ChildrenAsTriggers default set to true,all the LinkButtons should trigger an update without needing to register them. Just remove the trigger code. Once that is done if you still do not get a CommandArgument, post the UpdatePanel markup so that this can be duplicated.
No comments:
Post a Comment