473,396 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

sending parameter to UserControl, how?

Hey

ASP.NET 2.0

This the ObjectDataSource in my UserControl,
<asp:ObjectDataSource ID="odsMessage" runat="server"
SelectMethod="ExecuteMessage"
TypeName="AH.MyNetwork.BLL.Network.Message">
<SelectParameters>
<asp:ProfileParameter Name="user" PropertyName="UserName"
Type="String" />
<asp:Parameter Name="mode" Type="Boolean" />
</SelectParameters>
</asp:ObjectDataSource>

The problem is that I don't know a good way of setting the value of this
parameter "<asp:Parameter Name="mode" Type="Boolean" />" from the web page
in which the UserControl is placed..

This is how I've embedded this UserControl into the web page:
<%@ Register Src="~/Controls/Messages.ascx" TagName="Messages"
TagPrefix="mb" %>
<mb:Messages ID="Messages1" runat="server" />

Maybe I should create a private variable in the UserControl, and set the
ObjectDataSource to reference it, but I don't know how to reference the
private variable from the ObjectDataSource in the markup/source...

My UserControl is designed to show messages (received or sent message). I
have a web page named inbox.aspx where this control is used to show received
message. But now I want to use the same UserControl on a web page named
Outbox.aspx showing sent message. Then I need a way to tell the UserControl
if it's received or sent message it should display

Or maybe I should instead use 2 repeat controls + 2 ObjectDataSource objects
(1 for each repeat control) and hide or show them programatically... if the
UserControl should display received message, then hide the sent message
Repeater and display the Received Reapeater..

Any suggestions?

Jeff
Oct 17 '06 #1
3 3011
Create a PUBLIC property in the code section (or code behind if you use two
files). Once you compile (build website) you will see the new property and
you can set it either in the tags or in the code behind.

If you set a default condition in the controls load, you will want to have
property set reset the state of the control.

BTW, while this is a learning hurdle, it is a good coding style, as your
user controls become black boxes that are truly reuseable. One word of
caution: If you are not the only developer, either default the control or
throw custom exceptions that point to the property not being set (if it is
mandatory, that is). Otherwise, those maintaining the code will be lost,
esp. those who have not made the leap into making actual objects of their
user controls.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************************************************
Think outside of the box!
*************************************************
"Jeff" <it************@hotmail.com.NOSPAMwrote in message
news:e3**************@TK2MSFTNGP04.phx.gbl...
Hey

ASP.NET 2.0

This the ObjectDataSource in my UserControl,
<asp:ObjectDataSource ID="odsMessage" runat="server"
SelectMethod="ExecuteMessage"
TypeName="AH.MyNetwork.BLL.Network.Message">
<SelectParameters>
<asp:ProfileParameter Name="user" PropertyName="UserName"
Type="String" />
<asp:Parameter Name="mode" Type="Boolean" />
</SelectParameters>
</asp:ObjectDataSource>

The problem is that I don't know a good way of setting the value of this
parameter "<asp:Parameter Name="mode" Type="Boolean" />" from the web page
in which the UserControl is placed..

This is how I've embedded this UserControl into the web page:
<%@ Register Src="~/Controls/Messages.ascx" TagName="Messages"
TagPrefix="mb" %>
<mb:Messages ID="Messages1" runat="server" />

Maybe I should create a private variable in the UserControl, and set the
ObjectDataSource to reference it, but I don't know how to reference the
private variable from the ObjectDataSource in the markup/source...

My UserControl is designed to show messages (received or sent message). I
have a web page named inbox.aspx where this control is used to show
received message. But now I want to use the same UserControl on a web page
named Outbox.aspx showing sent message. Then I need a way to tell the
UserControl if it's received or sent message it should display

Or maybe I should instead use 2 repeat controls + 2 ObjectDataSource
objects (1 for each repeat control) and hide or show them
programatically... if the UserControl should display received message,
then hide the sent message Repeater and display the Received Reapeater..

Any suggestions?

Jeff

Oct 17 '06 #2
thanks, but just more thing:

This is the property I created in the UserControl:
private Boolean _mode;
public Boolean Mode
{
get { return _mode; }
set { _mode = value; }
}

This is the new markup in the web page using the UserControl (see the
property "Mode"):
<mb:Messages ID="Messages1" runat="server" Mode="true" />

Somehow the correct value of Mode isn't passed into ExecuteMessage, (it gets
"false", but I was expecting "true"). I think this is related to
"<asp:Parameter Name="Mode" Type="Boolean" />" (see blow for the entire
markup of my ObjectDataSource) which can't be correct...

Here is the markup of ObjectDataSource:
<asp:ObjectDataSource ID="odsMessage" runat="server"
SelectMethod="ExecuteMessage"
TypeName="AH.MyNetwork.BLL.Network.Message">
<SelectParameters>
<asp:ProfileParameter Name="user" PropertyName="UserName"
Type="String" />
<asp:Parameter Name="Mode" Type="Boolean" />
</SelectParameters>
</asp:ObjectDataSource>

How should I set the SelectMethod "ExecuteMessage" to use the custom
property "Mode"?

Jeff
"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote in
message news:eM**************@TK2MSFTNGP05.phx.gbl...
Create a PUBLIC property in the code section (or code behind if you use
two files). Once you compile (build website) you will see the new property
and you can set it either in the tags or in the code behind.

If you set a default condition in the controls load, you will want to have
property set reset the state of the control.

BTW, while this is a learning hurdle, it is a good coding style, as your
user controls become black boxes that are truly reuseable. One word of
caution: If you are not the only developer, either default the control or
throw custom exceptions that point to the property not being set (if it is
mandatory, that is). Otherwise, those maintaining the code will be lost,
esp. those who have not made the leap into making actual objects of their
user controls.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************************************************
Think outside of the box!
*************************************************
"Jeff" <it************@hotmail.com.NOSPAMwrote in message
news:e3**************@TK2MSFTNGP04.phx.gbl...
>Hey

ASP.NET 2.0

This the ObjectDataSource in my UserControl,
<asp:ObjectDataSource ID="odsMessage" runat="server"
SelectMethod="ExecuteMessage"
TypeName="AH.MyNetwork.BLL.Network.Message">
<SelectParameters>
<asp:ProfileParameter Name="user" PropertyName="UserName"
Type="String" />
<asp:Parameter Name="mode" Type="Boolean" />
</SelectParameters>
</asp:ObjectDataSource>

The problem is that I don't know a good way of setting the value of this
parameter "<asp:Parameter Name="mode" Type="Boolean" />" from the web
page in which the UserControl is placed..

This is how I've embedded this UserControl into the web page:
<%@ Register Src="~/Controls/Messages.ascx" TagName="Messages"
TagPrefix="mb" %>
<mb:Messages ID="Messages1" runat="server" />

Maybe I should create a private variable in the UserControl, and set the
ObjectDataSource to reference it, but I don't know how to reference the
private variable from the ObjectDataSource in the markup/source...

My UserControl is designed to show messages (received or sent message). I
have a web page named inbox.aspx where this control is used to show
received message. But now I want to use the same UserControl on a web
page named Outbox.aspx showing sent message. Then I need a way to tell
the UserControl if it's received or sent message it should display

Or maybe I should instead use 2 repeat controls + 2 ObjectDataSource
objects (1 for each repeat control) and hide or show them
programatically... if the UserControl should display received message,
then hide the sent message Repeater and display the Received Reapeater..

Any suggestions?

Jeff


Oct 17 '06 #3
odsMessage.SelectParameters.Add(new Parameter("Mode", TypeCode.Boolean,
Mode.ToString()));


"Jeff" <it************@hotmail.com.NOSPAMwrote in message
news:eV**************@TK2MSFTNGP05.phx.gbl...
thanks, but just more thing:

This is the property I created in the UserControl:
private Boolean _mode;
public Boolean Mode
{
get { return _mode; }
set { _mode = value; }
}

This is the new markup in the web page using the UserControl (see the
property "Mode"):
<mb:Messages ID="Messages1" runat="server" Mode="true" />

Somehow the correct value of Mode isn't passed into ExecuteMessage, (it
gets "false", but I was expecting "true"). I think this is related to
"<asp:Parameter Name="Mode" Type="Boolean" />" (see blow for the entire
markup of my ObjectDataSource) which can't be correct...

Here is the markup of ObjectDataSource:
<asp:ObjectDataSource ID="odsMessage" runat="server"
SelectMethod="ExecuteMessage"
TypeName="AH.MyNetwork.BLL.Network.Message">
<SelectParameters>
<asp:ProfileParameter Name="user" PropertyName="UserName"
Type="String" />
<asp:Parameter Name="Mode" Type="Boolean" />
</SelectParameters>
</asp:ObjectDataSource>

How should I set the SelectMethod "ExecuteMessage" to use the custom
property "Mode"?

Jeff
"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote in
message news:eM**************@TK2MSFTNGP05.phx.gbl...
>Create a PUBLIC property in the code section (or code behind if you use
two files). Once you compile (build website) you will see the new
property and you can set it either in the tags or in the code behind.

If you set a default condition in the controls load, you will want to
have property set reset the state of the control.

BTW, while this is a learning hurdle, it is a good coding style, as your
user controls become black boxes that are truly reuseable. One word of
caution: If you are not the only developer, either default the control or
throw custom exceptions that point to the property not being set (if it
is mandatory, that is). Otherwise, those maintaining the code will be
lost, esp. those who have not made the leap into making actual objects of
their user controls.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*********************************************** **
Think outside of the box!
*********************************************** **
"Jeff" <it************@hotmail.com.NOSPAMwrote in message
news:e3**************@TK2MSFTNGP04.phx.gbl...
>>Hey

ASP.NET 2.0

This the ObjectDataSource in my UserControl,
<asp:ObjectDataSource ID="odsMessage" runat="server"
SelectMethod="ExecuteMessage"
TypeName="AH.MyNetwork.BLL.Network.Message">
<SelectParameters>
<asp:ProfileParameter Name="user" PropertyName="UserName"
Type="String" />
<asp:Parameter Name="mode" Type="Boolean" />
</SelectParameters>
</asp:ObjectDataSource>

The problem is that I don't know a good way of setting the value of this
parameter "<asp:Parameter Name="mode" Type="Boolean" />" from the web
page in which the UserControl is placed..

This is how I've embedded this UserControl into the web page:
<%@ Register Src="~/Controls/Messages.ascx" TagName="Messages"
TagPrefix="mb" %>
<mb:Messages ID="Messages1" runat="server" />

Maybe I should create a private variable in the UserControl, and set the
ObjectDataSource to reference it, but I don't know how to reference the
private variable from the ObjectDataSource in the markup/source...

My UserControl is designed to show messages (received or sent message).
I have a web page named inbox.aspx where this control is used to show
received message. But now I want to use the same UserControl on a web
page named Outbox.aspx showing sent message. Then I need a way to tell
the UserControl if it's received or sent message it should display

Or maybe I should instead use 2 repeat controls + 2 ObjectDataSource
objects (1 for each repeat control) and hide or show them
programatically... if the UserControl should display received message,
then hide the sent message Repeater and display the Received Reapeater..

Any suggestions?

Jeff



Oct 17 '06 #4

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

Similar topics

3
by: A.M | last post by:
Hi, I have a property in my class like this: public string CurrentDisplayName { get { ... return s;
7
by: moondaddy | last post by:
I have a user control being used instead of a frame page. when the user clicks on a menu item I need to send the ID (integer value) of that menu as a parameter in the postback of the user control...
3
by: Alessandro Rossi | last post by:
Hi I developed a usercontrol with a textbox and an htmlInputHidden When I add my usercontrol in a webform, it works properly If I add my control in a template column of a datagrid i have some...
4
by: Michael Maes | last post by:
Hi, I have a UserControl with some "Children" (e.g. one ComboBox & one Label). I add the UserControl on a Form. If I perform a recursive scan through that Form's Control-Collection the...
5
by: Eþref DURNA | last post by:
how could I send a parameter to a runing csharp windows application?
1
by: h-h | last post by:
i have a class that take usercontrol and page as parameter like this makeSession( UserControl object) { /// To do something } could i use usercontrol and page together? how can i...
5
by: amatuer | last post by:
hi i have a link from page1 to page2. this link uses a querystring to transfer data. usually i have no problems using querystring t transfer data. bt for the first time page2 does not display.an...
0
by: Jesper Lund Stocholm | last post by:
I have problems with sending javascript to the client from a dynamically loaded usercontrol. I have a single page that dynamically loads controls into a table cell in a HTML-table. For one of...
3
by: chpadmamca | last post by:
Hi , I need this very urgent.please help me. I have to send a parameter on to the popup window which will open when a command button is clicked,again i need to display that parameter on the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.