Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

Can't access to web control textbox property

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nimrod Rotner - 06 Jun 2007 08:07 GMT
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);
 }
Alexey Smirnov - 06 Jun 2007 08:21 GMT
On Jun 6, 9:07 am, Nimrod Rotner <Nimrod
Rot...@discussions.microsoft.com> wrote:
> Hi,
> I built a web control wich has text box and public property that set or get
[quoted text clipped - 62 lines]
>    Response.Write(ctl.txt);
>   }

try to call WebUserControl11.txt

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.