Rot
@discussions.microsoft.com> wrote:
> Hi,
> I built a web control wich has text box and public property that set or get
> the text value of that text box.
> when i try to access that property i got error:
> "Object reference not set to an instance of ..."
> the compilation has no detected problem and i do not understand what is the
> problem.
> .ascx (web control)
> -------------------
> <%@ Control Language="c#" AutoEventWireup="false"
> Codebehind="WebUserControl1.ascx.cs" Inherits="WebGrid.WebUserControl1"
> TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
> Name:<asp:TextBox id="txtName" runat="server"></asp:TextBox>
> public class WebUserControl1 : System.Web.UI.UserControl
> {
> protected System.Web.UI.WebControls.TextBox txtName;
> private string num;
> public string txt
> {
> get
> {
> return txtName.Text;
> }
> set
> {
> txtName.Text=value;
> }
> }}
> -----------------------------------------------------
> .aspx (web form that uses the web control
> ....................................................
> <%@ Register TagPrefix="uc1" TagName="WebUserControl1"
> Src="WebUserControl1.ascx" %>
> <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
> Inherits="WebGrid.WebForm1" %>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
> <HTML>
> <HEAD>
> <title>WebForm1</title>
> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
> <meta name="CODE_LANGUAGE" Content="C#">
> <meta name="vs_defaultClientScript" content="JavaScript">
> <meta name="vs_targetSchema"
> content="http://schemas.microsoft.com/intellisense/ie5">
> </HEAD>
> <body MS_POSITIONING="GridLayout">
> <form id="Form1" method="post" runat="server">
> <uc1:WebUserControl1 id="WebUserControl11"
> runat="server"></uc1:WebUserControl1>
> <asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 16px; POSITION:
> absolute; TOP: 64px" runat="server"
> Text="Button"></asp:Button>
> </form>
> </body>
> </HTML>
> private void Button1_Click(object sender, System.EventArgs e)
> {
> WebUserControl1 ctl=new WebUserControl1();
> Response.Write(ctl.txt);
> }