AJAX Tabcontainer inside formview not inserting values

谁都会走 提交于 2019-12-12 10:03:44

问题


I have a TabContainer inside a data bound FormView (to present the information by category ex: Client Bio data, health history, financial details...). The Update and Insert of the formView doesn't work (posting NULL values to the database) - I guess the FormView cannot find the TextBoxes inside the tab container's tab panels.

Some of the forums say that it's because of the TabContainer's implementation (by design) of "INamingContainer", and a hack is to take control of the TabContainer's source code (ajax ctl toolkit's source code) and remove the "INamingContainer" interface from it... Too complicated to my taste .. I'm kinda lost.

Well is there a straight forward and better way to fix this? I'm dazzled to see that the toolkit has failed to implement this basic functionnality as for most developper ordering info (tab control) with formview is a common need.

Thanks in advance, Jeewai


回答1:


Answering my own thread... I got some great inside from the asp.net forum and decided to post the solution here: Reproducing the explanation that helped me out:

Hope that will clear out some questions to other users who may encounter the same issue.

Best, JY

Blockquote Hi JY,

The short answer is that when a Bind statement is compiled, there are some limitations on extracting values for an insert/update. If the controls within the FormView are then within another Naming Container (TabContainer and TabPanel are both naming containers), then the compiler can't resolve how to extract the value from the TextBox. I have a more detailed discussion of this on my blog at http://www.aarongoldenthal.com/post/2009/03/15/ASPNET-Databinding-Bind()-Method-Dissected.aspx.

To get around this, you'll need to extract the values manually, something like:

protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e) { // Get references to the controls TextBox LastNameTextBox= FormView1.FindControl("TabContainer1").FindControl("TabPanel1").FindControl("LastNameTextBox") as TextBox;

// Set update parameters in datasource
ObjectDataSource1.UpdateParameters["LastName"].DefaultValue = LastNameTextBox.Text;

}

Since FindControl only searches the current naming container, you'll need to dig through each naming container (FormView, TabContainer, and TabPanel) to get to the TextBox.

Hope that helps.

Aaron

Blockquote



来源:https://stackoverflow.com/questions/969784/ajax-tabcontainer-inside-formview-not-inserting-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!