Problem with web user control

Discussion in 'ASP .Net Web Controls' started by oterox, Nov 25, 2004.

  1. oterox

    oterox Guest

    Hi!
    I have a user control WebUserControl1.ascx with a textbox.I want to change
    the text of the textbox from another page but i get the error "object
    reference not set to an instance of the object".The code is:

    protected System.Web.UI.WebControls.TextBox txtUC;

    public string ucTexto
    {
    set
    {
    this.txtUC.Text = value;
    }
    }

    And in the webform i have this in the code-behind:

    protected WebUserControl1 uc1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    uc1.ucTexto = "ee";
    }
    and this in the aspx:

    <%@ Register TagPrefix="uc1" TagName="WebUserControl1"
    Src="WebUserControl1.ascx" %>
    <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
    Inherits="uc.WebForm1" %>

    <form id="Form1" method="post" runat="server">
    <uc1:WebUserControl1 id="WebUserControl11"
    runat="server"></uc1:WebUserControl1>
    </form>


    Thank you!
    oterox, Nov 25, 2004
    #1
    1. Advertising

  2. oterox

    David Jessee Guest

    if you're trying to change one page from another, you can't do that because
    keep in mind that yuo don't know when the server class for the page is
    instantiated. there are 2 "exceptions"

    if this second page you're referring to is a page in a frameset, then you're
    going to have to write javascript to change the second page

    If the second page is another httphandler that's being "Executed" or
    "transferred" to, then you can get the initial page by casting the
    request.handler into the initial page's type

    If you're trying to access a control in the main webform within your
    usercontrol, then you can get the textbox by saying
    Page.Findcontrol("text1").

    "oterox" <> wrote in message
    news:...
    > Hi!
    > I have a user control WebUserControl1.ascx with a textbox.I want to change
    > the text of the textbox from another page but i get the error "object
    > reference not set to an instance of the object".The code is:
    >
    > protected System.Web.UI.WebControls.TextBox txtUC;
    >
    > public string ucTexto
    > {
    > set
    > {
    > this.txtUC.Text = value;
    > }
    > }
    >
    > And in the webform i have this in the code-behind:
    >
    > protected WebUserControl1 uc1;
    >
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > uc1.ucTexto = "ee";
    > }
    > and this in the aspx:
    >
    > <%@ Register TagPrefix="uc1" TagName="WebUserControl1"
    > Src="WebUserControl1.ascx" %>
    > <%@ Page language="c#" Codebehind="WebForm1.aspx.cs"

    AutoEventWireup="false"
    > Inherits="uc.WebForm1" %>
    >
    > <form id="Form1" method="post" runat="server">
    > <uc1:WebUserControl1 id="WebUserControl11"
    > runat="server"></uc1:WebUserControl1>
    > </form>
    >
    >
    > Thank you!
    >
    >
    >
    >
    >
    David Jessee, Nov 26, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Reny J Joseph Thuthikattu
    Replies:
    1
    Views:
    554
    =?Utf-8?B?UHJha2FzaC5ORVQ=?=
    Dec 30, 2004
  2. ABC
    Replies:
    1
    Views:
    2,634
    Larry
    Oct 4, 2005
  3. ABC
    Replies:
    0
    Views:
    475
  4. Mad Scientist Jr
    Replies:
    0
    Views:
    633
    Mad Scientist Jr
    Mar 22, 2006
  5. ABC
    Replies:
    0
    Views:
    196
Loading...

Share This Page