0

I'm having trouble concerning using dynamic web controls inside a dynamically created Gridview. I need to create the Gridview in the code behind because I'm trying to create a plugin architecture for controls to be added to a web page. Here is some example code to replicate the problem.

ResultControl : WebControl in dll

protected override void OnInit(EventArgs e)
{
    GridView gv = new GridView();
    ButtonField f = new ButtonField();
    f.Text = "test";
    f.CommandName = "test";
    gv.Columnds.Add(f);
    Controls.Add(gv);
}

Then in code behind of a web form.

protected override void OnInit(EventArgs e)
{
    ResultControl rc = new ResultControl();
    Controls.Add(rc);
}

this error on page Control 'POPlugin_ResultControl_ctl00' of type 'GridView' must be placed inside a form tag with runat=server.

I've been searching for answers but the only things I've found are about exporting the GridView to excel files and I wasn't sure if that was entirely related. Perhaps my google fu is weak but I would much appreciate anyone shedding some light on this situation.

geek_factorial
  • 85
  • 1
  • 1
  • 6

1 Answers1

0

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.buttonfield.aspx. "The ButtonField class is used by data-bound controls (such as GridView and DetailsView) to display a button for each record that is displayed." But i don't see any datasource in your code.

Tomas Voracek
  • 5,886
  • 1
  • 25
  • 41
  • I wasn't specific enough I think in my previous post, and I thought that the test code I specified would apply because it did in my plug-in code. I have a dll that contains overloaded webcontrols that I created. In the OnInit of said controls I have code exactly like above but when I view the page that adds those dynamically add web controls in my dll I get an error like this. Control 'POPlugin_ResultControl_ctl00' of type 'GridView' must be placed inside a form tag with runat=server. This is the actual problem I don't understand why I'm having. – geek_factorial Jan 24 '11 at 22:36
  • It turns out, I was not adding in the form tag, because I thought I was adding it to a specific control on the aspx page but I was adding it just to the Pages Control collection and not the ContentHolder for my master page. Stupid Error that I've been grudging over for like 3 days. Thanks for the help! – geek_factorial Jan 24 '11 at 22:49