Problem with web user control

O

oterox

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!
 
D

David Jessee

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").
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top