all groups > asp.net building controls > november 2004 >
You're in the

asp.net building controls

group:

Problem with web user control


Problem with web user control oterox
11/25/2004 9:13:11 PM
asp.net building controls:
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!




Re: Problem with web user control Leon Friesema
11/26/2004 7:54:44 PM
[quoted text, click to view]

Well, that's because you need to refer to the control like
((WebUserControl1)Page.FindControl("WebUserControl1")).ucTexto = "ee";

Casting before refering and use the Id, not the tagname

AddThis Social Bookmark Button