Solved

c#,asp.net- passing data to user controls

Posted on 2009-03-30
10
457 Views
Last Modified: 2012-05-07
Hi,
I want to pass a value to a user control on my aspx page , I have done this when i have data in a repeater, but dont know how to pass the data when I dont have a repeater. My control is just in a div

I want to pass the value of the HatID, i have a method that returns the hatid which is GetRandomImageURL()

Thanks
<div>

<HatPhotoControl:HatPic HatID='<%#DataBinder.Eval(Container.DataItem,"HatID")%>' runat="server" />

</div>

Open in new window

0
Comment
Question by:CharlieDev
  • 4
  • 3
  • 3
10 Comments
 
LVL 11

Expert Comment

by:b_levitt
ID: 24019631
i beleive  you just have to add a property to the code behind of the user control:
private string hatID="";
public string HatID
{
  get
  {
     return this.hatID;
  }
  set
  {
     this.hatID = value;
  }

}
0
 

Author Comment

by:CharlieDev
ID: 24019644
thanks  b levitt, i do already have that code , its just the passing of the actual value on the aspx page that I cant get
0
 
LVL 7

Expert Comment

by:vbwizardry
ID: 24019665
Use <%=[Your Value]%> if you binding to a property on the page. Also You can pass a value in you user control's onInit or OnLoad events ;) by assigning the value in code.
0
 

Author Comment

by:CharlieDev
ID: 24019725
Thanks, how would i put in the hatId?
I tried <HatPhotoControl:HatPic HatID='<%"HatID"%>' runat="server" />

and it hasnt passed the value
0
 
LVL 11

Expert Comment

by:b_levitt
ID: 24019749
Oh I think I see what you're saying.

Give the UserControl an ID....
<HatPhotoControl:HatPic ID="MyHatPic" HatID='<%#DataBinder.Eval(Container.DataItem,"HatID")%>' runat="server" />

Then assign the property in the code behind of the aspx page...
MyHatPic.HatID = "my value";
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 7

Assisted Solution

by:vbwizardry
vbwizardry earned 100 total points
ID: 24019953
Yes but do not assigne  HatID='<%#DataBinder.Eval(Container.DataItem,"HatID")%>'  since you control is not part of databound container such as repeater ;)
0
 
LVL 11

Accepted Solution

by:
b_levitt earned 400 total points
ID: 24019984
thanks vb, i meant to take that out.  So the correct answer is:
Give the UserControl an ID....
<HatPhotoControl:HatPic ID="MyHatPic" runat="server" />

Then assign the property in the code behind of the aspx page...
MyHatPic.HatID = "my value";
0
 
LVL 7

Expert Comment

by:vbwizardry
ID: 24020084
yp
0
 

Author Comment

by:CharlieDev
ID: 24020371

Thanks using
 MyHatPic.ID= "my value";

worked :)
0
 

Author Closing Comment

by:CharlieDev
ID: 31597469
cheers!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now