Problem in accessing web form data in user controls when create user control dynamically

HI.
I have a problem using web user control. I designed a user control named NewsForm. This user control contains some web form elements like <asp:textbox>. When I add it in an .ASPX page, all things may be true. I can know which user filles in textbox (for example and other controls)
<%@ Register TagPrefix="uc1" TagName="NewsForm" Src="NewsForm.ascx" %>
and
<UC1:
NewsForm id="newsForm" runat="server"></UC1:NewsForm>

But when i create it in code behined dynamically, however user control has web form controls but their value are blank
for example

//aspx containing control page
protected NewsForm newsForm;
protected System.Web.UI.HtmlControls.HtmlGenericControl containerInPage;
       
        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            newsForm=(NewsForm)LoadControl("NewsForm.ascx");
             containerInPage.Controls.add(newsForm);
        }

......

and User Control Page:
protected System.Web.UI.HtmlControls.HtmlGenericControl containerInUserControl;
        protected System.Web.UI.WebControls.TextBox TextBox1;

        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            if(Page.IsPostBack)
            {
                containerInUserControl.InnerHtml+=TextBox1.Text;      //Text value is blank but I filled it!
                                                                                                                 //Also a validator checks that Text was not blank!
            }
        }


Can any one solve this problem for me?

thanks in advance
0
hassan_behzadian
10/30/2005 7:23:21 AM
asp.net.web-forms 93655 articles. 5 followers. Follow

2 Replies
1827 Views

Similar Articles

[PageSpeed] 45

I don't see where you're filling the TextBox. Sounds like you're trying to populate the UC controls from the parent page, and for that, you need public properties on the UC to be accessed from the parent page. Maybe this will help:
   http://forums.asp.net/1095904/ShowPost.aspx

Just create a public property on the UC to set the TextBox as I did in the link for a DDL, called let's say, TextBoxText and then:

private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            newsForm=(NewsForm)LoadControl("NewsForm.ascx");
           // Added this line:
            newsForm.TextBoxText = "somevalue";
             containerInPage.Controls.add(newsForm);
        }


NC...
0
NC01
10/30/2005 11:16:30 AM
To learn more about User Control I recommend that you read this article: 

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/usercontrols.asp




HighOnCoding
Wanna get high!
0
azamsharp
10/30/2005 4:22:06 PM
Reply:

Similar Artilces:

access controls on web user control x from web user control Y
I have 2 web users controls in a page and I would like to get or set the selected values of a few dropdown boxes on web user control X from web user control Y and I also would like to know how to access functions that are on a web user control X from a web user control Y, is this possible? How can I do it? User can access and set the values of the User Control from .aspx page through properties,using javascript and in code-behind of aspx page.The details of it are shown below Using PropertiesIf the Sample.ascx control has two textboxes and submit button.You can access the valu...

How to access individual controls from a form containing the web user control containing those controls
 Below is a block of code in my .aspx form named default.aspx. In this form I load a web user control. I then add it to a place holder control.(Lines 3 and 4 below) So how do I access the individual controls in my web user control? I want to set the properties on those controls, but I am baffled as to how to access the control. For example I have a text label control named "label3". How do I access this control. Because for example, under certain situations I want to hide that control. ( Label3.Visible = false;)  1    if(!Page.IsPostBack) 2&nb...

Web User Control to Web User Control...
Hi, I have 2 User controls on a page and want Control1 to call a method of Control2. Is this Possible? Example: Con1 = Datalist showing products, each with a Quantity Box and a Button. Con2 = Repeater showing Cart Preview (name, Price) in page.aspx. When I click on the button on the DataList in Con1 it adds the item into the Session based Cart. However it does not update the Cart Preview. I need to call BindPreview() in Con2 in order to update the Cart Preview... Does that make sense? argh! any help much appreciated! PeteWeb Design Nottingham, UK Well I can call BindPreview() from m...

Persisting data in a web user control, which contains a list of other web user controls.
 Hi All, I have a control I've created, which can have a number of child controls - also user controls - stored as an ArrayList, which can be added wither a design time or programmatically.My problem is when I add to the list programmatically, it doesn't persist them. So if I add 3 child controls in step 1 of a wizard, with the aim that those three will be visible inside the parent in step 3, what happens is that the parent has no child controls and the item count is 0.Can anyone help? Thanks in advance.Code:Parent Control Markup: <%@ Control Language="C#" Auto...

Access a Web User Control Method from a Web Form
I'm trying to pass the Selected Index value from a web user control in a web form to the user controls selectedIndexchanged Sub.  I can't seem to figure out how to pass the information that I need to the user control and have it execute the sub routine. In the SelectedInedxChanged Sub I have a switch Statement and I want to get the index value from the web form where the user control is located and compare it to each case and then to have it execute the code for the case that it matches. What do I need to do? Hi, I am not sure if I understood your question correctly. I su...

Pass data from Web User Control to Web Form
I have a Web Form that contains a Web User Control. The WUC displays dynamic content. I want to change the TITLE property of the Web Form, based on the contents of the WUC. For example, if the WUC displays information about Horses, I want to change the page title to "HORSES" by passing the string to the parent Web Form. I have tried playing with parameters and such, but I can't remember how I did this in the past. PLEASE HELP!~o0 Spin-Monkey Oo~ The best way to do this is by creating a public property on your web user control and accessing that from your web form. Check ...

Access SqlDataSource on Web Form from a Web User Control...
Hello, I want to access a SqlDataSource on a Web Form fromout. a Web User Control. To do this, I have in my code behind of the Web User Control the folowing code: DropDownList1.DataSource = (this.Page.FindControl("SqlDataSource3") as SqlDataSource);DropDownList1.DataTextField = "Name;DropDownList1.DataValueField = "NameIDropDownList1.DataBind(); But, the control (ic. SqlDataSource3) is not found. Even other controls like labels and buttons are not found with the FindControl. What am I doing wrong? Thanks Andromedaris     This is not much of a surprise,...

Web form Access to User Control Data
I need to access the value of a User Control Public variable from the code behind page of the form containing the user control. Right now I can't see the user control from the code behind page. This contol is not dynamically loaded....

Problems with UpdatePanel, Web User Control and Dynamic Controls Creating
Hi,In a Page, i have a button that's outside an UpdatePanel, but that triggers him. That UpdatePanel get refreshed with a Web User Control inside it. The Web User Control, has come logic to dynamically create some Controls (TextBox and other simple controls), and he does that very well, and the UpdatePanel get refreshed ok and the controls get rendered to the browser. The problem is when i click in a Button inside the Web User Control (not dynamically created), and i can't get the controls values in the server-side. Before the server side event of the Button Click, i re-create all the contro...

User Control controls not created when dynamically creating user control
  Have created a user control for displaying and editing a dynamically number of values. The user control contains two labels and an edit box. When dynamically loading the user control I get an error when the control itself tries to change setting on the fields within the user control.   Why doesnt this work? It works okay if I dont load it dynamically but create a user-control-instance in the aspx-page but thats no solution.   Thankyou!     Here is my code:   ucDataValue.ascx   <%@ Control Language="C#" AutoEventWireup="true&...

user control data entry form, use same codebehind as web form?
Hi All, I have a quesiton about the approach I'm taking. I have a series of report forms which I have been in the process of consolidating to a single, generic page and subs/functions in a single code-behind. All the reports can use the same set of data entry elements (a dropdown, a radio list, and a textbox). I'm trying to convert these elements to a user control. However, this user control seems to need to inherit differently than the rest of the code-behind. I've been using a single class in the code behind. Is it feasible to separate out the data entry? the code behind im...

Problem creating new web forms and user controls
I have been coding .net for almost a year. Three days ago I created a new project and then some new web forms. Compiled, then viewed the site. I get an error saying it cannot load type - then shows the inherited class for the code behind of the page. This is only happening in certain sites, and we have strict procedures when creating them. They are all the same. Any help would be great Check if you are creating the name spaces properly...(if you have any) rebuild the whole project and then try it out...Hey! It compiles! Ship it! Cheers, Venugopal Mallarapu. Visit : My Blog...

Web Form and Web User Control
Hello, I have a Web User Control (ascx) that includes a button. This button has an onclick event method. This Web User control is included into a Web Form. (thru LoadControl). However, when I click on the button, the event method is not executed. What should I include in order it works fine? Thanks in advance. GAA. Using Loadcontrol is using dynamic controls and when using dynamic controls you must recreate the same dynamic controls ono postback to econstruct the page control tree. It is best if you do this during the Page PreInit event. How complex are your controls ...

UpdatePanel within a web user control resets data of controls outside the user control
Hello, I have a usercontrol on my page which displays a running marquee text. It makes use of an UpdatePanel (within the user control) to refresh the marquee text (within the updatepanel) at periodic intervals. For this I added a timer control and its tick event as an async postback trigger for the UpdatePanel. I have a lot of textboxes and dropdown list boxes (all with runat=server) on the page outside the above user control. These are also contained in different UpdatePanels. Problem is, when the user control does a postback to refresh the marquee text, it causes some of...

Web resources about - Problem in accessing web form data in user controls when create user control dynamically - asp.net.web-forms

Placebase team at Apple file “Schematic Maps” patent dynamically detailing important data
In a report from Computerworld way back in 2009, we learned that Apple had quietly acquired Maps API company Placebase. Then, founder of Placebase ...

Apple's Lightning port dynamically assigns pins to allow for reversible use
... a closer look at how Apple's new Lightning connector works, and has come to the conclusion that the 8 pins on each side of the plug are dynamically ...

In a dynamically typed language, is it a bad idea to return different data types?
In some cases, returning different types from a single function works.

Urlbox Launches Screenshots-as-a-Service Platform to Dynamically Update Galleries
... changes. Launched yesterday, Urlbox allows anyone with a gallery displaying website screenshots to automate the process and keep them dynamically ...

Everything.me launcher dynamically adapts to what you’re doing right now
... phone according to what you’re doing. Perform a search for ‘football’ and your background will change to the NFL logo. A launcher that dynamically ...


A YouTube Experiment Resizes the Player Dynamically
There's a new YouTube experiment that changes the video player's size, depending on the browser window's size. When resizing Chrome's window, ...

Apple Granted “Dynamically Changing Cursor for User Interface” Patent, Originally Filed in 2003
... a utility patent that covers the use of the mouse cursor that changes according to the context of the task it is engaged in. Called a “Dynamically ...

Atmel's FPSLIC II Dynamically Reconfigurable SoC Supports "Silicon-Sharing" For Peripherals & Interfaces ...
Silicon-Sharing Fits 200K Gate Design into 40K Gate FPSLIC II's, Cuts Power Drain by 97%

Everything.me Launcher Wants to Dynamically Change Phones Based on Location, Interests, and Mental State ...
What if your phone’s launcher dynamically changed based upon interests, your location, or topics you had in mind at a specific moment? A new ...

Resources last updated: 12/9/2015 9:20:07 PM