This is a migrated thread and some comments may be shown as answers.

EditForm UserControl controls generate from code-behind

1 Answer 88 Views
Grid
This is a migrated thread and some comments may be shown as answers.
n/a
Top achievements
Rank 1
n/a asked on 28 Mar 2009, 05:40 PM
Hi,

I'm trying to use the user control as the edit form, this is working fine but now I want to generate the input boxes from code behind on page load as this is a dynamic input form. Unfortunately I'm having problems them to bind with the Container object as this only seems to exist when declaring it in the aspx. Is there anyway to get hold of this object from code behind? maybe from the Page object (which references the container page with the grid on it) or by passing it in as  properties/eventargs on the user control.

Here is my user control code example..

public partial class WebUserControls_EditForm : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        TextBox txt1 = new TextBox();
        
        txt1.Text = DataBinder.Eval(Container, "DataItem.Txt1").ToString();

        this.Controls.Add(txt1);
    }
}

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 Mar 2009, 07:40 AM
HI Christophe,

One suggestion will be to use hidden fields and populate that using the  DataBinder.Eval(container object) and access these fields from the code behind.

Or use this:
  
   private void Page_Load  
    {  
       TextBox txt1= new TextBox();
       txt1.Text = DataBinder.Eval(NamingContainer, "fieldname" ));  
  
    }   


Shinu
Tags
Grid
Asked by
n/a
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or