473,591 Members | 2,871 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reference a control

A basic question:
In a content page I access a TextBox from code behind with no problems
(something like Me.MyField.Text ="1").

This is the portion of aspx file :
<asp:Content ID="secMessagge " ContentPlaceHol derID="cphFoote r" Runat="Server">
<asp:TextBox ID="MyField" runat="server" BorderStyle="In set"
BorderWidth="3p x"
ReadOnly="True" Style="left: 485px; position: relative; top:
2px; text-align: center"
Width="52px"></asp:TextBox>
</asp:Content>

In a second Content Section of the same page I then added a GridView.
The Select command in the DataSource reference the TextBox like this:
.... SelectCommand=" SELECT * FROM [Contracts] WHERE ([ContractID] =
@ContractID)" ....

<SelectParamete rs>
<asp:ControlPar ameter ControlID="MyFi eld" Name="ContractI D"
PropertyName="T ext" Type="string" />
</SelectParameter s>

Problem:
1 - running the page I get an error saying control MyField is not found.
2 - in programming phase, the selecting list of controls shows all controls
twice (?).

The problem is surely related to the presence of a Master page. Without it a
similar page is runnning.
Can I get some help?
Thanks.

--
bruno
Oct 17 '06 #1
4 3057
Hello Bruno,

As for the DataSource control referencing problem, it is caused by the
DataSourceContr ol and ParamterSource control are in different
ContentPlaceHol der of the Master_Content page. The DataSourceContr ol can
only locate control that are in the same parent container, for master page
with multiple contentPlaceHol ders, controls in different Content holder can
not be found by DataSourceContr ol in other content holder.

Based on my research, you can consider using the following ways to overcome
the problem:

1. Instead of using ControlParamter , you can define a normal parameter
which doesn't has a linked source (control, querystring.... ). e.g
==========
<asp:SqlDataSou rce ............... >
<SelectParamete rs>
<asp:Paramete r DefaultValue="" Name="CategoryI D" Type="Int32" />

</SelectParameter s>
</asp:SqlDataSour ce>
===========

And runtime, you programmtically retrieve parameter value from the source
control and add the value into Select Command's parameter, you can do it in
the DataSourceContr ol's "Selecting" event. e.g

=-=============
protected void SqlDataSource1_ Selecting(objec t sender,
SqlDataSourceSe lectingEventArg s e)
{

e.Command.Param eters["@CategoryI D"].Value =
int.Parse(txtCa tegory.Text);
}
=============== ===

2. Since the cause of the problem is due to paramter control and datasource
control in different Content Holder, you can add a hidden TextBox control
in the same contentHolder of the DataSourceContr ol and let
DataSourcecontr ol's ControlParamete r refer to this hidden control, and you
need to add some code in the original TextBox.Load event to synchronize the
value between them. e.g

#the following page use a hiddden TextBox(txtTemp ) to act as a linker
between the two content holder to pass parameter value.
=============== ===========
<asp:Content ID="Content1" ContentPlaceHol derID="ContentP laceHolder1"
Runat="Server">
<asp:TextBox ID="txtCategory " runat="server"
OnLoad="txtCate gory_Load">1</asp:TextBox>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHol derID="ContentP laceHolder2"
Runat="Server">
<asp:TextBox ID="txtTemp" runat="server" Visible="false" ></asp:TextBox>
<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:NorthwindCon nectionString %>"
OnSelecting="Sq lDataSource1_Se lecting" SelectCommand=" SELECT
[CategoryID], [CategoryName] FROM [Categories] WHERE ([CategoryID] =
@CategoryID)">
<SelectParamete rs>

<asp:ControlPar ameter ControlID="txtT emp" PropertyName="T ext"
Name="CategoryI D" DefaultValue="1 " />
</SelectParameter s>
</asp:SqlDataSour ce>

<asp:DetailsVie w ID="DetailsView 1" runat="server"
AutoGenerateRow s="False" DataKeyNames="C ategoryID"
DataSourceID="S qlDataSource1" Height="50px" Width="125px">
<Fields>
<asp:BoundFie ld DataField="Cate goryID" HeaderText="Cat egoryID"
InsertVisible=" False"
ReadOnly="True" SortExpression= "CategoryID " />
<asp:BoundFie ld DataField="Cate goryName"
HeaderText="Cat egoryName" SortExpression= "CategoryNa me" />
</Fields>
</asp:DetailsView >
<asp:Button ID="Button1" runat="server" Text="Button"
OnClick="Button 1_Click" />
</asp:Content>
=============== =============== ==========

=========code behind========= =======
protected void txtCategory_Loa d(object sender, EventArgs e)
{
txtTemp.Text = txtCategory.Tex t;
}
=-=============== ======

Hope this helps. If there is anything unclear, please feel free to let me
know.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

=============== =============== =============== =====

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.


Oct 18 '06 #2
Thank you Steven for your clear explanation.
Let's consider a Page with a Menu on the left, a common area on the bottom
side and a central area that changes depending on the user choices and the
application logic. A very common Web application.
I'm new on ASP.NET development and self learning and till now I didn't use
MasterPage and solved the problem with a .aspx file in which the body area
has many panels (<DIV runat="server" ..>) I change the Visible attriute
accordingly.
In this case I don't have the problem of different ControlPlaceHol ders, but
from an architectural point of you, do you think this is the standard
suggested approach? What about MasterPage?
Thank you Steven.
--
bruno
"Steven Cheng[MSFT]" wrote:
Hello Bruno,

As for the DataSource control referencing problem, it is caused by the
DataSourceContr ol and ParamterSource control are in different
ContentPlaceHol der of the Master_Content page. The DataSourceContr ol can
only locate control that are in the same parent container, for master page
with multiple contentPlaceHol ders, controls in different Content holder can
not be found by DataSourceContr ol in other content holder.

Based on my research, you can consider using the following ways to overcome
the problem:

1. Instead of using ControlParamter , you can define a normal parameter
which doesn't has a linked source (control, querystring.... ). e.g
==========
<asp:SqlDataSou rce ............... >
<SelectParamete rs>
<asp:Paramete r DefaultValue="" Name="CategoryI D" Type="Int32" />

</SelectParameter s>
</asp:SqlDataSour ce>
===========

And runtime, you programmtically retrieve parameter value from the source
control and add the value into Select Command's parameter, you can do it in
the DataSourceContr ol's "Selecting" event. e.g

=-=============
protected void SqlDataSource1_ Selecting(objec t sender,
SqlDataSourceSe lectingEventArg s e)
{

e.Command.Param eters["@CategoryI D"].Value =
int.Parse(txtCa tegory.Text);
}
=============== ===

2. Since the cause of the problem is due to paramter control and datasource
control in different Content Holder, you can add a hidden TextBox control
in the same contentHolder of the DataSourceContr ol and let
DataSourcecontr ol's ControlParamete r refer to this hidden control, and you
need to add some code in the original TextBox.Load event to synchronize the
value between them. e.g

#the following page use a hiddden TextBox(txtTemp ) to act as a linker
between the two content holder to pass parameter value.
=============== ===========
<asp:Content ID="Content1" ContentPlaceHol derID="ContentP laceHolder1"
Runat="Server">
<asp:TextBox ID="txtCategory " runat="server"
OnLoad="txtCate gory_Load">1</asp:TextBox>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHol derID="ContentP laceHolder2"
Runat="Server">
<asp:TextBox ID="txtTemp" runat="server" Visible="false" ></asp:TextBox>
<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:NorthwindCon nectionString %>"
OnSelecting="Sq lDataSource1_Se lecting" SelectCommand=" SELECT
[CategoryID], [CategoryName] FROM [Categories] WHERE ([CategoryID] =
@CategoryID)">
<SelectParamete rs>

<asp:ControlPar ameter ControlID="txtT emp" PropertyName="T ext"
Name="CategoryI D" DefaultValue="1 " />
</SelectParameter s>
</asp:SqlDataSour ce>

<asp:DetailsVie w ID="DetailsView 1" runat="server"
AutoGenerateRow s="False" DataKeyNames="C ategoryID"
DataSourceID="S qlDataSource1" Height="50px" Width="125px">
<Fields>
<asp:BoundFie ld DataField="Cate goryID" HeaderText="Cat egoryID"
InsertVisible=" False"
ReadOnly="True" SortExpression= "CategoryID " />
<asp:BoundFie ld DataField="Cate goryName"
HeaderText="Cat egoryName" SortExpression= "CategoryNa me" />
</Fields>
</asp:DetailsView >
<asp:Button ID="Button1" runat="server" Text="Button"
OnClick="Button 1_Click" />
</asp:Content>
=============== =============== ==========

=========code behind========= =======
protected void txtCategory_Loa d(object sender, EventArgs e)
{
txtTemp.Text = txtCategory.Tex t;
}
=-=============== ======

Hope this helps. If there is anything unclear, please feel free to let me
know.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

=============== =============== =============== =====

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.


Oct 18 '06 #3
Thanks for your reply Bruno,

I think whether to use MasterPage depend on the size and maintenance
quirement of your project. If it is a small internat application contains
limited number of pages, I think it surely ok to ingore master page here.
And just use <divor html <tableto structure your web page layout(I
prefer table).

Master page just help us make our website templaterize so that we can
easily define the common part of all the page in an website or web
application. And it make maintain web pages in large application much more
convenient.

Therefore, if you think it ok(and even more easier for implement your code
logic) that we do not use master page in the application (considered over
project size, maintenance, ......), just forget it and use the simplest way
you can get. If you think make pages consistent and maintainable is more
important, then we can should use MasterPage. And if you meet any problems
communication between different part(content section) on a masterized page,
you should use some other means to resolve it (like the solutions in my
last reply).

How do you think? Please feel free to let me know if you have any further
questions or ideas on this.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 18 '06 #4
Hi Steven thanks for your reply. Now I have a more clear idea on the two
different choises (masterpage or tables and div).
sincerely
--
bruno
"Steven Cheng[MSFT]" wrote:
Thanks for your reply Bruno,

I think whether to use MasterPage depend on the size and maintenance
quirement of your project. If it is a small internat application contains
limited number of pages, I think it surely ok to ingore master page here.
And just use <divor html <tableto structure your web page layout(I
prefer table).

Master page just help us make our website templaterize so that we can
easily define the common part of all the page in an website or web
application. And it make maintain web pages in large application much more
convenient.

Therefore, if you think it ok(and even more easier for implement your code
logic) that we do not use master page in the application (considered over
project size, maintenance, ......), just forget it and use the simplest way
you can get. If you think make pages consistent and maintainable is more
important, then we can should use MasterPage. And if you meet any problems
communication between different part(content section) on a masterized page,
you should use some other means to resolve it (like the solutions in my
last reply).

How do you think? Please feel free to let me know if you have any further
questions or ideas on this.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 18 '06 #5

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

Similar topics

2
10537
by: Pkpatel | last post by:
Hi, I keep getting this error every time I try to load crystalreportviewer on a webform with a dataset. Here is the error: -------------------------------------------------------- Server Error in '/Cr_Dataset' Application. ----------------------------------------------------------- ---------------------
39
7625
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down indicate: a) That I don't know enough b) Passing arguments by ref is bad
0
1733
by: Patrick | last post by:
This is a C# post. I'm using VB.NET to create an add-in for the Google Sidebar, and have implemented the OnDetailsView method. NOTE : I've come across this same problem (error message) even in C#. I tried placing a label control and setting the reference of this new lable into the 'details_control' parameter. This worked.
1
3012
by: Martine | last post by:
Hi there! I have a problem with programmatically adding user controls to my mobile webforms. If I load my usercontrol programmatically (in the Page_Load), the object is instantiated, I have access to the methods and properties from the Page_Load, no problem there. But as soon as I want access to the user control from another procedure on the same page, I get the next error message: "Object reference not set to an instance of an...
9
2168
by: Moe Sizlak | last post by:
Hi There, I am trying to write the selected value of a listcontrol when a button is clicked and I keep getting the error "object not set to a reference of an object". The libox itself is in a usercontrol and all i'm really needing to do is get the selected value when the button is clicked on the form. Can someone tell what I need to include in my page to get this working ? Moe <><
6
6111
by: blash | last post by:
Can someone help me? I really don't have a clue. My company staff told me they often got such error: "Object reference not set to an instance of an object." when they are in search result page then tried to access 2nd, or 3rd, etc page. The problem is it happens sometimes - sometimes when they clicked refresh button, then everything is ok. Now they told me it happens more frequently. but I have tried by myself many times and never got...
1
1505
by: Don | last post by:
I created a Web User Control in my project and need to use it in a datagrid. The data in this control needs to be updated and the control has several properties that need to be databound. Using the designer I created a a dataGrid with an Edit, Update, Cancel column, and an empty template column. I have overridden ItemDataBound to instantiate my control, set the properties using DataItems, and add this control to the template column...
7
3185
by: Samuel | last post by:
Hi, I am building a page that makes use of user control as a templating technique. The following is that I have in mind and it is actually working: Root/ -- login.aspx -- login.aspx.vb -- UC/ ----- Classic/
2
2577
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a good while and I'm getting really frustrated now! My problem is this - my custom controls periodically disappear from my
9
1402
by: =?Utf-8?B?VG9tbXkgTG9uZw==?= | last post by:
I don't know if the following is what you are looking for, but to me what you described was using a control array. If you were using vb6 that would be easy, the following articles hopefully explain using control arrays in .net Hope they help? http://visualbasic.about.com/od/usingvbnet/l/bldykctrlarraya.htm ...
0
7934
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8236
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8362
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8225
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6639
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5732
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1465
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1199
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.