PC Review


Reply
Thread Tools Rate Thread

Can't access to web control textbox property

 
 
=?Utf-8?B?Tmltcm9kIFJvdG5lcg==?=
Guest
Posts: n/a
 
      6th Jun 2007
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);
}

 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      6th Jun 2007
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
> 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);
> }


try to call WebUserControl11.txt

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Control Source Property for TextBox Public Microsoft Access Forms 4 21st May 2008 06:57 PM
Create a TextBox control with BorderColor property sreenish Microsoft Dot NET 1 29th Jul 2005 09:40 AM
TextBox.Text property empty after hiding and showing the control. Alexander Microsoft C# .NET 1 19th Jul 2004 05:23 PM
Setting the web control textbox property enabled = FALSE Gill Smith Microsoft ASP .NET 4 22nd May 2004 09:20 PM
How to add Textbox's PasswordChar property in PropertyGrid Control siddhiash Microsoft VB .NET 7 28th Nov 2003 06:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:54 PM.