473,545 Members | 2,469 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Access value of TextBox inside ascx control from codebehind

This is what I am doing

public class GridCustomPagin g : System.Web.UI.P age

{

protected System.Web.UI.W ebControls.Data Grid DgSearch;

protected System.Web.UI.H tmlControls.Htm lForm frmsearch;

protected System.Web.UI.W ebControls.Labe l CurrentPage;

protected System.Web.UI.W ebControls.Labe l TotalPages;

protected System.Web.UI.W ebControls.Link Button FirstPage;

protected System.Web.UI.W ebControls.Link Button PreviousPage;

protected System.Web.UI.W ebControls.Link Button NextPage;

protected System.Web.UI.W ebControls.Link Button LastPage;

protected System.Web.UI.W ebControls.Text Box Categories1_Tex tsearch;

protected Int32 _currentPageNum ber = 1;

private void Page_load(objec t sender, System.EventArg s e)

{

if ( !Page.IsPostBac k )

{

BindData();

}

}



private void BindData()

{

Response.Write( Categories1_Tex tsearch.Text);

}
At this point I get this error: Object reference not set to an
instance of an object.
I tryed these two options:
Categories1_Tex tsearch =
(TextBox)this.P age.Parent.Find Control("Catego ries1_Textsearc h");
and
Categories1_Tex tsearch =
(TextBox)this.P age.FindControl ("Categories1_T extsearch");

Still get the same error

Do I have to reference the ascx control page inside codebehind? How to
do it?

categories.ascx is the control page.

Categories1_Tex tsearch is the name of the textbox inside
categories.ascx . Actually the original name is only Textsearch, but
Frameworks, renames it behind the scenes. Categories1_Tex tsearch is
what I see in the source of the html.

I tried to expose the public properties with no success. But that does
not work since both the aspx and ascx are using codebehind.

Thanks
Rod
Nov 18 '05 #1
1 3368
The usercontrol variable has a FindControl method, use that. As you see, the page level FindControl method won't dig into the usercontrol.

"rodrigo" <rc**********@y ahoo.com> wrote in message news:39******** *************** **@posting.goog le.com...
This is what I am doing



public class GridCustomPagin g : System.Web.UI.P age

{

protected System.Web.UI.W ebControls.Data Grid DgSearch;

protected System.Web.UI.H tmlControls.Htm lForm frmsearch;

protected System.Web.UI.W ebControls.Labe l CurrentPage;

protected System.Web.UI.W ebControls.Labe l TotalPages;

protected System.Web.UI.W ebControls.Link Button FirstPage;

protected System.Web.UI.W ebControls.Link Button PreviousPage;

protected System.Web.UI.W ebControls.Link Button NextPage;

protected System.Web.UI.W ebControls.Link Button LastPage;

protected System.Web.UI.W ebControls.Text Box Categories1_Tex tsearch;



protected Int32 _currentPageNum ber = 1;



private void Page_load(objec t sender, System.EventArg s e)

{

if ( !Page.IsPostBac k )

{

BindData();

}

}









private void BindData()

{



Response.Write( Categories1_Tex tsearch.Text);



}


At this point I get this error: Object reference not set to an
instance of an object.


I tryed these two options:
Categories1_Tex tsearch =
(TextBox)this.P age.Parent.Find Control("Catego ries1_Textsearc h");
and
Categories1_Tex tsearch =
(TextBox)this.P age.FindControl ("Categories1_T extsearch");

Still get the same error

Do I have to reference the ascx control page inside codebehind? How to
do it?

categories.ascx is the control page.

Categories1_Tex tsearch is the name of the textbox inside
categories.ascx . Actually the original name is only Textsearch, but
Frameworks, renames it behind the scenes. Categories1_Tex tsearch is
what I see in the source of the html.

I tried to expose the public properties with no success. But that does
not work since both the aspx and ascx are using codebehind.



Thanks
Rod

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
13720
by: adiel | last post by:
Hello, I am trying to access the properties and methods from a user control within the code-behind file for a webform but I am receiving the message: Name 'MenuBar1' is not declared It does not recognize the user control in the code behind... Here is the code for the user control: MenuBar.ascx:
2
3012
by: paul meaney | last post by:
All, myself and another developer have been staring blankly at a screen for the past 48 hours and are wondering just what stunningly obvious thing we are missing. We are trying to load up 2 or more user controls dynamically by adding to a placeholder defined in page_load. I've included the sample code for how we are accessing one. The...
2
3102
by: Benedict Teoh | last post by:
I created a dropdownlist containing day, month and year field and expose a property to assign a date. When I call from a aspx page and assign the value, the new date is not displayed until a submit is performed. How do I force the usercontrol to display the newly assigned date? I don't have this problem if I place the two dropdownlist and the...
1
2118
by: digitalego | last post by:
Sorry if the title is a little confusing... Here is the problem. I am working with a "default.aspx" page that uses a user control I made: ------------------------------ | default.aspx | ------------------------------ <%@ Page language="C#" CodeBehind="ChartPage.cs"
2
1813
by: Alixx Skevington | last post by:
Hi there peeps, I am having a problem have just started to use usercontrols, and I am hitting a problem. I get the error message above, now each control has a table, and 1 asp:textbox control. Now when I first got this error I just put the form tags around the table in the control with the runat=server set. But however I get the...
2
1964
by: N. Demos | last post by:
I have a user control with code behind of which two instances are created/declared in my aspx page. The aspx page has code behind also, as I need to access methods of the usercontrols on page submit. I've read several post here and articles on the web on this topic. What little I have learned from them is that you have to pre-compile the...
1
6838
by: Will Gillen | last post by:
I know this has probably been asked before, but I can't seem to find a solid answer in any of the archives. First, before my question, please forgive my limited knowledge of the event lifecycle and page loading/rendering lifecycle.... Ok, now for the question: I have an ASPX page (page.aspx), and I have a UserControl (control.ascx). The...
5
2862
by: c676228 | last post by:
Hi, I guess I am confused. In aspx script, I mean (you won't use Codebehind="enrollinfo.aspx.vb", but mix code with html and code together) You can access user control's property directly. Since I am useing visual studio .net, the html and code are seperated. I have the following aspx code which has two user controls: <%@ Register...
1
2211
by: =?Utf-8?B?Tmltcm9kIFJvdG5lcg==?= | last post by:
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.
0
7490
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7682
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7935
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7780
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6009
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5069
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3479
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3465
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1037
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.