Home » Visual Studio

Problem with xmlmapping and dynamic content controls


I'm trying to add controls dynamically with the help of document fragments in VSTO 2010. Short version (where frag.docx contains a content control with the tag "tag1"):


string xPathName = "ns:employees/ns:employee[2]/ns:name";
Globals.ThisDocument.SelectContentControlsByTag("tag1")[1].XMLMapping.SetMapping(xPathName, ThisDocument.prefix, Globals.ThisDocument.employeeXMLPart);

Complete code can be found here: http://www.mediafire.com/?3505iovi814ez7w

This was adapted from the code posted here: http://msdn.microsoft.com/en-us/library/bb398244.aspx

The first problem is that the custom xml part doesn't seem to be updated when I change the data of the custom controls. E.g. change the name of an employee.

The second problem is that the title dropdown list isn't populated with it's proper values from the schema.

What have I missed? Is there a better way of doing this?



Dear All,


I have a grid, in that i have edit button column, If user wants to click on the edit button I need to open a modal window to display the records for the particular row data from database.


And also I am using SMS form to send sms, If user click on the send button I need to open the modal window and to dislpay a preview of the sms from the textbox of the same form.


Please help me to achieve these two functionality.


Thanks in advance.




Arun Kumar


Hello Everyone,

  I am getting this error "Only Content controls are allowed directly in a content page that contains Content controls". I am using a single aspx page and not a separate cs file. Now, to write code inside aspx page, I am using <script> tag. Now, my problem is inside one of the method I have to use <script> tag. Now, when i use that this error comes. Eg

  <script runat="server">

 ........inside it coding done

  // Method inside which I have to use this tag again

  public void abc()


........initially some code.........

Response.Write("<script>document.getElementById('PaylForm').submit();</script></body></html>");   //This gives error




Thanks in Advance.



FYi I am using SPD.

I saved dispform.aspx with the new name dispform1.aspx. Then I did some modification in the pages, everything was correctly. After some time I re-open new page using SPD, I am  not able to open the page in design/code mode. It is not giving me any error only showing message in status bar retrieving dispform1.aspx. I wait almost 1 hours, but no luck.

When I try to run this new page I am getting following error

"Only Content controls are allowed directly in a content page that contains Content controls"

Earlier it was working and I have not made any changes.

I need to recover it, as I did customize the whole page, please advise



Hey community,

I am quite new to the WPF and currently try to create a custom window control for an entity editor. The editor will hold a domainobject (e.g. an employee of a company) whose fields can be editted using the editor visually (name, surname, corporate id, etc...), and then be saved back to the database using generic "Save" and "Apply" buttons.

Since I want the editor to be reusable for different entities, I intended to have the common buttons for saving and so on at the bottom of the window, and the rest be filled dynamically with editor-specific controls (textboxes, labels...).

In the end, it should be used something like this using XAML:

<EditorWindow x:Class="Redheads.PmisSharp.Client.Ui.Wnd.Editor.EditorBaseWindow"
       d:DesignHeight="300" d:DesignWidth="300">
		<!-- The actual individual controls for this editor -->

In this example the mentioned "Save" / "Apply" buttons should be implicitly added at the bottom of the window. But I don't know how to achieve this at the moment. Can anyone give me a clue or point me to some links that can help me out? I think that ControlTemplates might do the trick, but I am not so sure about that.

Any advice is appreciated, thanks!

- PuerNoctis

Rich Text Content control turns into a plain text content after association using Word 2007 content control toolkit.

Is this normal?
i have created a dynamic table in which i have created a dynamic gridview in C# and i have put a button to create controls dynamically.The problem is that whenever m pressing a link button on gridview,the gridview disappears,i think dynamic controls are lost on postback..please help me..............



Recently I am working with a project which mix between Windows Form and WPF Control. The background structure is where WPF Control will be hosted within the Windows Form. Reason of doing so is to make use of the MDI Parent feature of Windows Form. I am trying to create a base class which inherit System.Windows.Forms.Form to ease the creation and hosting of WPF Control, below are the relevant codes:

1. POC.Core.BaseView is going to use to be inherited by WPFControl


using System;
using System.Windows.Controls;

namespace POC.Core
  publicclass BaseView : UserControl
    //--- Default Properties ---//public BaseView()


2. POC.Core.WPFHoster with the dynamic object of WPFView which will inherit POC.Core.BaseView, this base class is going to be inherited by windows forms.

using System;
using System.Windows.Forms;
using System.Windows.Forms.Integration;

namespace POC.Core
  public class WPFHoster<WPFView> : Form
    where WPFView : BaseView, new()
    private ElementHost _hoster;
    private WPFView _view;

    public WPFHoster()

      this._view = new WPFView();
      this._hoster = new ElementHost();
      this._hoster.Dock = DockStyle.Fill;
      this._hoster.Child = this._view;


3. POC.Controls.LoginView is the WPFControl that inherit the POC.Core.BaseView, I won't show the XAML here as it does not affect the prove of concept.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using POC.Core;

namespace POC.Controls
  publicpartialclass LoginView : BaseView
    public LoginView()


4. POC.WinClient.LoginForm is the form that will inherit WPFHoster and using LoginView as the actual UI


using System;
using POC.Core;
using POC.Controls;

namespace POC.WinClient
  publicclass LoginForm : WPFHoster<LoginView>
    public LoginForm() : base()


The codes above work perfectly and the UI (POC.Controls.LoginView) shown during debug mode. But, when i try to view the POC.WinClient.LoginForm during design mode, error below shown:

The designer could not be shown for this file because none of the classes within it can be designed. The designer inspected the following classes in the file: LoginForm --- The base class 'POC.Core.WPFHoster' could not be loaded. Ensure the assembly has been referenced and that all projects have been built.

The reason why I would like to view the POC.WinClient.LoginForm in design mode is to adjust the height and width of the form according to the UI designed (XAML) in POC.Controls.LoginView. It is very time consuming and non-programmer friendly if I get my programmer to modify the height and width of POC.WinClient.LoginForm using code behind.

I am able to view and modify (height & width) POC.WinClient.LoginForm in design mode if I change the POC.Core.WPFHoster to the code below, but POC.Core.WPFHoster would never serve it targeted purpose anymore:

using System;
using System.Windows.Forms;
using System.Windows.Forms.Integration;

namespace POC.Core
  public class WPFHoster : Form
    public WPFHoster()
Anyone have any clue?




I have a custom user control that contains within it a repeater control. Inside this repeater I programmatically add another custom user control, which contains a text box and a custom validator. This final custom user control can be added any number of times depending on the application's logic. All of this is part of a wizard step.

When the user completes the step, if any of the data added to the text boxes is incorrect the validator gets fired on post back. However, because I can have any number of these controls added to the repeater, the user has to scroll down to see any of the incorrectly completed boxes.

Due to the controls being added dynamically it is not possible to use a validation summary control - I have tried!!! Therefore, is there away I can use JavaScript to position a cursor or to jump to each incorrectly completed textbox without the user needing to scroll down the page? For example, if there are 10 textboxes, and textboxes 8 and 9 have numbers inside them inside strings, then the JavaScript should jump textbox 9.


Hello Everybody ,I have this problem,if anyone could help me i'll be so gratefull.

I had been created some dynamic radio buttons in a loop inside a dinamy table which is inside an UpdatePanel , but i can not handle the events my code is below:

public void MetodoCreacion()

RadioButton RBtn = null;
Table table = new Table();
TableRow row = null;
TableCell cell = null;

for (int i = 0; i < 5; i++)
row = new TableRow();
cell = new TableCell();
RBtn = new RadioButton();

RBtn.ID = "RBGN_" + i.ToString();
RBtn.GroupName = "RBGN1";
RBtn.Text = "Opcion " + i.ToString();
RBtn.CheckedChanged += new EventHandler(RBtn_CheckedChanged);
RBtn.AutoPostBack = true;



UpdatePanel1_UpdatePanelAnimationExtender.Controls .Add(table);

public void RBtn_CheckedChanged (object sender, EventArgs e)
Label1.Text = ((RadioButton)sender).ID;

and the controls doesent call the event ...

thanks a lot


Ive been stuck on this one for a month:

So I have a custom control that has a list of textboxes, and a button that will dynamically add a new textbox to the list.

 So I have an addTextbox() function, that will do something like

TextbBox t = new TextBox()

 then I add it to the page.  So adding a new textbox works fine, but I have values that I want to put into each textbox and upon each page load, the values get replaced.  What I need to do is get the textboxes from the viewstate so I can use their values for other textboxes, but since they are created anonymously, im not sure how I can do that.  I tried to get the unique name and put all of them into an arraylist, then upon the next page load, load the names from the list, but the unique name isnt unique.  Thanks


    I have several RTF Content Controls in Word 2007; they have tags.

    When I select the content of one of my RTF CC and paste it into another one also the tag will be copied. So the second RTF CC will have two tags, screwing my application.

   I noticed that after the pasting a pasting option button appears, and I can deselect the option "Keep Content Controls". In this case the tag is not copied. Exactly what I needed!

  So I want to be sure that this option is programmatically deselect every time the user copy and paste between different RTF CC.

   But I can I achieve this? I can't find any documentation on this option! I can't even register a macro to see what kind of code will pop out! Obviously there must be somewhere the code to do this, but I can I find it where to look for it.

 Any suggestions?

Thanks, Lauro

I am developing my application using ASP.net 2010 and .net frame work 4.0. I am trying to access the controls in the master page in my content page.

I did the following in my code,

1. In the content page i added the directive, <%@ MasterType VirtualPath="~/Site.Master" %>

2. I tried to access the master page controls from the content page code behind by using the command,

       Master.Button1; and also tried using Master.findcontrol(Button1).

 I get a error that says Button1 does not exist in the content page and also button1 was not displayed in the intelli sense. Button1 is not placed inside a contenplaceholder in master page. I am not sure what i am missing.

Looking forward for help.

Thanks in advance.







I need to provide my client with the facility to manage a set of dynamic lists of questions in sharepoint. Basically and admin needs to be able to alter sets of questions, possible stored in a list, which are then provided to other users for data entry.

I originally thought that that I could provide a solution using infopath forms, with the form being submitted to a web service and parsed into question tuples before being stored in a db, or stored in a list that was later parsed to db using client object model. If the admin needed to add questions or modify existing questions, they would edit the form in infopath then resubmit the form to the form library for web access.

After a bit of investigation I am concerned this approach of managing question definitions by modifying and resubmitting infopath forms might not be the way to go. Might be too complicated for the user and may lead to many problems when we want to extract the data. An alternative would be to allow the admin to maintain question definition in a list with question text, data type being set for each question. At runtime the question definitions would be  pulled from the list/db and used in a webpart to dynamically generate an aspx form (collection of text boxes, dropdowns etc).

I would appreciate any advice here. Have folks tried either approach before etc?




One of our content lists is missing the controls and the content.   The user tried to edit the list and something she did made the list disappear.  The list heading it there so it's not like it was deleted.  And the view all site content shows that it wasn't been edited in two weeks.  What should I start by trying?




I'm hosting a webbrowser control and loading a URL that contains a a small form that is embedded in the larger web page content. After the page is loaded, I'm modifying the html/css in memory to deleted various html elements (mostly divs) that surround the embedded form div so that the end result is all you see in the browser is the sub form.

Problem I'm having is that i want to resize the webbrowser control to fix the displayed content so I can then center webbrowser control in the C# form. I can't figure how to do this.

I tried stuff like:

	webBrowser1.Height = webBrowser1.Document.Body.OffsetRectangle.Height;
webBrowser1.Width = webBrowser1.Document.Body.OffsetRectangle.Width;

But the browser continues to display scrollbars. I'm not that far off but enough to cause the scroll bars to appear. I new to working with the webbrowser and don't really understand how the cumulative sizing of all the nested elements works and how these correspond to the browser control size.



I want to programmatically  insert the content of a docx file into a content control of another docx file. I can see 2 ways to achieve this operation :

1- using InsertFile method

2- using InsertXML method

What is the best way to do this?



Visual Studio 2010

Working on a content page (.aspx page with associated master page)

Not all of the content place holders from the master page are represented on the content page (have been deleted)

Can go to the master page, find the place holder I want, return to content page and type out the "content" tag.

Is there an easier way? Can I drag a content tag in from a toolbox somewhere? Can I "re-apply" a master page to a content page and have it restore missing place holders? Looking for the lazy way out.


Hi guys I m new to forum

I m stuck up in following code what i want to do is every time user clicks the button it should display 1 more panel (in project button is for showing for experience input fields so if some person have more than one experience than by simply click this button it should show one more set of controls  )

please check code below

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class AddExprience : System.Web.UI.Page
    Label[] Company_label_arr=new Label[50];
    TextBox[] Company_textbox_arr = new TextBox[50];

    Label[] Position_label_arr = new Label[50];
    TextBox[] Position_textbox_arr = new TextBox[50];

    Label[] Responsiblity_label_arr = new Label[50];
    TextBox[] Responsiblity_textbox_arr = new TextBox[50];

    Label[] ResonForLeaving_label_arr = new Label[50];
    TextBox[] ResonForLeaving_textbox_arr = new TextBox[50];

    Panel[] panel_arr=new Panel[50];
    Int32 count=0;
    Label lsd = new Label();
    Control[] control11=new Control[50]; 
    protected void Page_Load(object sender, EventArgs e)

    protected void AddExpButton_Click(object sender, EventArgs e)
        count = System.Convert.ToInt32(Session["count1"]);

    public void addControl()
        panel_arr[count] = new Panel();
        panel_arr[count].CssClass = "code";
        panel_arr[count].Width = 412;
        // panel1x.Direction = ContentDirection.LeftToRight;

        Company_label_arr[count] = new Label();
        Position_label_arr[count] = new Label();
        Responsiblity_label_arr[count] = new Label();
        ResonForLeaving_label_arr[count] = new Label();

        Company_label_arr[count].Text = "Company";
        Position_label_arr[count].Text = "Position";
        Responsiblity_label_arr[count].Text = "Responsibility";
        ResonForLeaving_label_arr[count].Text = "Reson for leaving";

        Company_textbox_arr[count] = new TextBox();
        Position_textbox_arr[count] = new TextBox();
        Responsiblity_textbox_arr[count] = new TextBox();
        ResonForLeaving_textbox_arr[count] = new TextBox();




        foreach(Panel panel1 in panel_arr)
        lsd.Text = "hello";
        Panel3.Controls.Add(new LiteralControl("<br>"));
        Session.Add("count1", count);
    protected void UpdatePanel1_Load(object sender, EventArgs e)


I have a TextBox to indicate product quantity and ComboBox with a list of products.

These two controls are in StackPanel (important i keep the structure :-)).

 I need the TextBox tooltip to say "input product quantity", if a product in the ComboBox is selected.

If no product is actually selected in the ComoBox, the TextBox ToolTip should (instead) say "please select first product" . 

My problem is setting the TextBox ToolTip template trigger to refer to the ComboBox name ...

Any suggestions that lead to a solution are welcome.


Thanks, Paul

I have customized a Page Layout to include a custom Data Form View Web Part that will allow users to enter comments on a news story page in a publishing site.

I was having a difficult time because when I clicked the button to save the data to the list, everything saved correctly, but the control was redirecting me to the AllItems.aspx page of the list.  This wasn't the desired behavior since the end user would prefer to see that their comment was posted on the news story page and wouldn't know what the AllItems.aspx page was for.

The save button that was created in the XSL seciton of the web part was:

<SharePoint: SaveButton runat="server" ControlMode="New" id="savebutton1" />

Microsoft has documented a RedirectUrl property on this button that I figured could change what page was loaded after the user saved the form data.  However, try as I might I could not get it to work.

Some more searching lead me to this article:


Which details how to create a "Form Action" for a save button rendered in the XSL of a DataFormWebPart.  This was a great article, but it doesn't detail the code that Sharepoint Designer outputs for this action.  After following the instructions, I discovered this code for a button:

<input type="button" value="Save" name="btnSave" onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={}')}" />

When used instead of my SharePoint: SaveButton above, the form saved it's data correctly, and the current page that the form was submitted from was reloaded for the user.

You could also put any URL in the __redirect={} that you want, for example __redirect={http://www.google.com} or __redirect={/news/PressReleases/}

Notice that there are no quotes around the URLs passed into the __redirect directive.

Didn't find this documented anywhere, but it seemed pretty useful so I thought I would share.



<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure