.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Adding Controls dynamically in the infopath form - A standard Expense Entry scenario

Posted By:      Posted Date: September 23, 2010    Points: 0   Category :SharePoint


I am having a requirement where I need to create an Expense Report Entry form using Infopath 2010. 

1) The form would have pre-defined columns/Controls like Exp.Type(drop-down) , Details , Location, Amount , Curruncy, Date etc..

2) User can enter/update as many line items as possible by clicking Add/Update/Delete for the each line items. So basically its like adding the same row dynamically.

3) When User Submits, I need to capture this data and post it to SAP where I am using SAP web Services.

Can you please suggest if this is possible in InfoPath form ?

If Yes, how can I achieve this dynamic line items functionality in InfoPath

And how can I read the data using the code so that I can Post it to the WebService? 

View Complete Post

More Related Resource Links

Adding controls to a form dynamically


How to add checkboxes at a particular positon in a application dynamically.

That is ,I want to add checkboxs depending on the no of items in a collection and i even want to name it.How can i do it?

Can i get any sample code for it?

Adding carriage returns between 2 dynamically created controls in an HtmlTableCell


The title pretty much explains it. Here is what i'm trying to do...

 Private Sub LoadGrid_CommentsField(ByVal Row As HtmlTableRow, ByVal BookingNumber As String, ByVal CommentsText As String)
  Dim Txt As TextBox
  Dim Cmd As ClickOnceButton.ClickOnceButton

  Txt = New TextBox
  Txt.ID = "txtComment_" & BookingNumber
  Txt.CssClass = "TFAppControls"
  Txt.TextMode = TextBoxMode.MultiLine
  Txt.MaxLength = 500
  Txt.Width = New Unit(95, UnitType.Percentage)
  Txt.Text = CommentsText

  Row.Cells(cComments).InnerHtml &= "<br/>"

  Cmd = New ClickOnceButton.ClickOnceButton
  Cmd.DisableAfterClick = True
  Cmd.Text = "Save Comments"
  Cmd.ID = "cmdSaveComments_" & BookingNumber
  Cmd.CssClass = "TFAppButtons"
  Cmd.EnableViewState = False
 End Sub

On the line where i try and update the InnerHtml, i get the following error; "Cannot get inner content of  because the contents are not literal."

this.controls.add - not always adding to parent form

My current code (snippet below) iterates through user info and adds the same custom control to a form based on how many "Meals" (1-6) the user has selected.  It appears that all even # controls (the second, fourth and sixth) are added to the previously added control, rather than the parent form, when I later try to dispose the controls by iterating through this.controls, only 1, 3 and 5 appear, the others appear as children to 1, 3 & 5. I've reduced controls size, etc. to make sure they're not overlapping (if that can force inheritence?) but no luck.  Anyone have suggestions on what to look at or other guidance? public void drawMealPanel(Meal m, int x, int y) { Controls.MealDisplay md = new Controls.MealDisplay(m); md.Name = m.name; md.Tag = m.id.ToString(); md.Left = x; md.Top = y; md.DragDrop += new System.Windows.Forms.DragEventHandler(this.MealView_DragDrop); md.DragEnter += new System.Windows.Forms.DragEventHandler(this.MealView_DragEnter); this.Controls.Add(md); }

Dynamically adding User Controls -- newbie question!

I am new to ASP.NET (coming from ColdFusion, thank goodness I'm away from that!).  And I am have THE hardest time understanding how to work with forms in ASP.NET.  Here's what I am doing:Dynamically add User Controls to a PlaceHolder based on some int value (which currently is passed in a HiddenField).Fire an event if the WebControls inside of the User Control change, then handle that event in the Main Page (i.e. save the input to DB)When the user clicks the "Next/Continue" button, the next controls for the next page are loaded.And I guess maybe I just can't seem to get how things work in ASP.NET, because I am really struggling with the general idea of how ASP.NET flows.  Should I be dynamically loading the controls in Page_Init, or Page_Load?  Or should I load the controls when the buttonclick event is fired?Do I have to add the axCtrl.OnDataChange += new EventHandler(HandleAxControlDataChange); line on Page_Load?  Or should I put this in When I first load the UserControl, I need to initialize some WebControls within the UserContorl.  Is there a way to know if I have loaded new user controls into my placeholder?  I can't use Page.IsPostback, because after the first page, every page is a postback from the buttonclick.Any help for this confused newbie would be GREATLY appreciated!!Here's what I have: pu

Expense Reimbursement Approval template cant open infopath form

hi, i just created a site using the template Expense Reimbursement Approval. but when i click on the Expense link and click new it try to open infopath form but it gives me this error: The form template was created with a newer version of InfoPath. This form template was created by InfoPath version 12.0.0. do i have to use infopath 2007 to open this form? thnx

InfoPath Forms : Adding rows dynamically from a SQL table along with a 'Delete' button per row


My requirement is something like this:

In a Task Approval form, I want to have a view which shows all the rows in a particular SQL table (in a infopath repeating table?). Along with each row, there should also be a button, on clicking which the row should disappear from the infopath view table. Do you think InfoPath can handle all this? :) 

To summarize:

1. How do I add rows to a table dynamically?

2. Per row, how do I create a button dynamically?

3. How do I remove the row from the view when the button is clicked?

Adding controls dynamically


Hi All,
I am creating a questionnaire in a gridview. The questions, answer options and answer control are under CMS. So I am building the questionnaire 'on the fly' adding controls to the page dynamically.

In Page_Load during !Page.IsPostback I bind the question text to the gridview then have another method that iterates through the gridview rows, and adds the controls to a cell eg.gvr.Cells[1].Controls.Add(rbl); The page renders correctly - I see all questions, answers and answer control eg, DropDownList, RadioButtonList, TextBox etc.

The problem is when I try to save the selected options, FindControl cannot find the controls. Even though when I view source I can see all ctrls and ids. I've seen a lot of posts about this issue and CreateChildControl, EnsureChildControl seem to be the route to take. But I don't unserstand how to use them. Can anyone point me to a good example?

And if anyone can explain why it is not working. The page 'looks' to be rendering correctly. Why then are the controls not being found on the postback? Are the controls not being added to the ViewState?


How to set alignments of form controls dynamically.

I have a form containing two panels. In both panels there are two labels and textboxes. I set the 'Center In Form' property of the labels and textboxes to 'Horizontally' and 'Vertically' in design time respectively. But as the form is resizable, when the size of the form is increased or decreased at runtime the controls are no longer center aligned in the panels. How can I handle this problem (provided the main form needs to remain sizable)? Please help.
Thanks in advance

InfoPath error: One or more required custom controls in this form cannot be created


I have an InfoPath 2007 form published to a form library in MOSS 2007.  This form opens in InfoPath and is not browser-enabled.

The form suddenly stopped working for me and 1 other user.  I'm a farm admin and the user only has contributor rights on the form library (and site and subsite).  Everyone else with appropriate permissions can access existing forms that use the template and can create new forms using the template.

When either one of us tries to open the form, we get:

InfoPath cannot open the following file: http://site/subsite/formlibrary/filename.xml?OpenIn=PreferClient&NoRedirect=true&XmlLocation=/subsite/formlibrary/filename.xml.
One or more required custom controls in this form cannot be created.

No errors in the web front end event log or SharePoint log files.  No errors in my client PC's event log.

I've tried the following without success:

Opening the template and publishing it to a new list. 
Published the template to a new content type on this list and a new list. 
Dumped IE cache and reset IE settings.
Rebooted the computer.
Checked permissions on the list to make sure they were correct.

Last change made to the farm:

I performed the work around change to the web

Dynamically adding content to page outside of the aspnet form from within a UC


I have a uc which generates a html form  that should auto-submit when the browser loads the page, so I need to add the form to the page before the </body> tag - outside the asp.net form, id like my UC to work without having any requirements on its parent page / masterpage.

i have managed to add a literal inside the body tag by calling the following inside CreateChildControls on the parent page
Me.Form.Parent.Controls.AddAt(0, ltl)
however this required the body to have runat="server" and the code to be added to the user control's parent page. ( this also seems to cause the viewstate to be lost after postback)

Is there any way i can append the string to the rendered html inside the body but outside the <form></form> from within the UC code

Incase it makes a difference the UC is being added dynamically to the page.

dynamically create a checkbox inside the infopath form?


I have a shared database that drives Windows Mobile Apps, Windows WPF Clients and now rich client InfoPath form (this wont be used an InfoPath web, only the rich office client)...

This database contains a list of daily changing of Audit Questions depending on the week and season etc.

I want to make a call to the database from InfoPath, pull back a list of LabelName and Controltype_id  1=checkbox 2 = textbox

In the Onload Event of the InfoPath form I want to dynamically create Textbox/Checkboxs with the label names from the database, with an question_id per answer.  Then the user will disconnect their internet and drive to the place without service (large metal multiroom coolstores without 3G service)  and fill in the checklist, the the user presses a button, and it evaluates all the answers and makes the background colour grey or black, and change the font colour to white. then the user presses the submit it back to the server when they are back in 3G service again.  

How can this be acheived? can someone send me some example code that works, thanks.

Please dont reply with "this is not possible", make the impossible possible.
1,000s of people told me I couldn't get barcodes into InfoPath even with the cursor on any form field. But I did it.
10,000s of people to

Adding Approval WorkFlow to InfoPath Web form "This Form Has Been Closed"


I have used the following link:



I can view the form, create a new form and publish the form to the library on submit.  However, When I try to create an approval WorkFlow on the site, I get "This Form Has Been Closed". 

I have a task list created and I have the form library set up to display web part pages. I published the form from the main SharePoint server.  How can I add a workflow to this Web Form?

Programatically adding rows to nested repeating tables in Infopath Form based on a criteria


Req Nested Repeating Table:







Dynamically Create Controls in ASP.NET by Using Visual C# .NET

This article demonstrates how to dynamically create a control for an .aspx page. The sample project does the following:
Creates two TextBox controls.
Verifies that the contents (TextBox.text) and the attributes of the TextBox are saved across posts to the server.
Illustrates handling events that are posted by a dynamically-created control

Dynamically Create Controls in ASP.NET with Visual Basic .NET

This step-by-step article describes how to dynamically create controls for an ASPX Web page.

The sample project does the following:
It creates two TextBox controls.
It verifies that the TextBox contents (TextBox.text) and attributes are saved across posts to the server.
It describes how events that are posted by a dynamically created control are handled.

dynamically adding sql server columns based on number of files in fileuploader


I want to create a new table to sql database at runtime.  The column names would be "Name", "Date", "Event".  I would also like to have one more column name "Image" but the problem is that since the amount of images will vary, I want the application to count the amount of files in the Multiple fileuploader and then add a image column to the table for the respected amount of files. 

For example if i am uploading 3 files in the multiple fileuploader, the names should be "Name", "Date", "Event", "Image1", "image2", Image3"

I also would like that table name to be name dynamically from the textbox Name when the user enters the information.


I have the following code to make a new table, but I dont know how to name the fields at runtime like previously asked please help!!!


Dim objConn As New SqlConnection("Server=<servername>;uid=<userid>;pwd=<password>;database=master")


InfoPath 2007: Designing Form Templates With The New Features Of InfoPath


InfoPath 2007 is an XML forms designer and editor, and a fully featured and integrated member of the Office family. This article takes a sneak peek at some of its new features.

Scott Roberts and Hagen Green

MSDN Magazine August 2006

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend