Connecting Tech Pros Worldwide Help | Site Map

Passing parameters to user controls

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 17th, 2005, 05:20 PM
Akira
Guest
 
Posts: n/a
Default Passing parameters to user controls

Hello.
I'm having problem with passing parameters from .aspx file to user
control.
Could anyone tell me how to pass parameters from .aspx file to user
control(.ascx) and how to recieve parameters at .ascx?
Thank you for your help!

  #2  
Old November 17th, 2005, 05:20 PM
Cowboy \(Gregory A. Beamer\)
Guest
 
Posts: n/a
Default Re: Passing parameters to user controls

Open the CodeBehind file and add the user control to the controls
collection. Not sure why, but, by default, a user control is placed on the
page but never given a corresponding line in the CodeBehind file.

Dim NameOfControlOnPage As MyControl
protected MyControl NameOfControlOnPage;

You can see the lines of other controls in your CodeBehind, so the above
templates are suspect. Once you do this, you will be able to use:

NameOfControlOnPage.PropertyOne = "";

to set values.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
Author: ADO.NET and XML: ASP.NET on the Edge

************************************************** **************************
****
Think Outside the Box!
************************************************** **************************
****
"Akira" <akira@regonline.com> wrote in message
news:3239e228.0307020936.20748177@posting.google.c om...[color=blue]
> Hello.
> I'm having problem with passing parameters from .aspx file to user
> control.
> Could anyone tell me how to pass parameters from .aspx file to user
> control(.ascx) and how to recieve parameters at .ascx?
> Thank you for your help![/color]


  #3  
Old November 17th, 2005, 05:20 PM
Karl Seguin
Guest
 
Posts: n/a
Default Re: Passing parameters to user controls

use properties...or public fields :)

user control:

private _ValueID as integer
Public Property ValueID as integer
Get
return _ValueID
ENd Get
Set (byval value as integer)
_ValueID = value
end set
end property

From within the user control you can simply refer to "ValueID" from
thereonin to get the value that was assigned to it by the parent.


Parent:
Two methods
<control:name runat="server" id="cntrl" ValueID=3 />

in codebehind
cntrl.ValueID = 3


Karl

"Akira" <akira@regonline.com> wrote in message
news:3239e228.0307020936.20748177@posting.google.c om...[color=blue]
> Hello.
> I'm having problem with passing parameters from .aspx file to user
> control.
> Could anyone tell me how to pass parameters from .aspx file to user
> control(.ascx) and how to recieve parameters at .ascx?
> Thank you for your help![/color]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.