Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Controls (http://www.velocityreviews.com/forums/f63-asp-net-web-controls.html)
-   -   Problem with web user control (http://www.velocityreviews.com/forums/t774876-problem-with-web-user-control.html)

oterox 11-25-2004 08:14 PM

Problem with web user control
 
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 11-26-2004 03:02 PM

Re: Problem with web user control
 
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" <oterox@gmail.com> wrote in message
news:uF9Bcty0EHA.3588@TK2MSFTNGP14.phx.gbl...
> 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!
>
>
>
>
>





All times are GMT. The time now is 09:21 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.