Affiliate Marketing
Forum Search

Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)  
Old 22-03-06
uklejon's Avatar
Registered User
 
Join Date: Aug 2003
Location: Shropshire
Posts: 815
Thanks: 0
Thanked 0 Times in 0 Posts
uklejon is an unknown quantity at this point
  ASP.NET Help

I'm have a user control that gets a value from a cookie and also looks at a db and gets a value from that, these values are put into labels.

The values are UserName.Text and InBox.Text

Code:
<asp:Label ID="UserName"
                runat="server" Font-Names="Verdana" Font-Size="X-Small" Width="92px"></asp:Label>

<asp:Label ID="InBox" runat="server" Font-Names="Verdana" Font-Size="X-Small"></asp:Label>
This user control is then inserted into many pages.

What i want to do is use the values of UserName.Text and InBox.Text in the web form .aspx page that the control sits in. I could just do the connections again but seems to waste a DB connection when the values are in the UC.

Been struggling wwith this for ages, i'm sure its simple.

Any ideas?? (with a code example is poss)

Jon Pretending to be Carol
__________________
Jon

UK Link Exchange - Find Link Exchange Partners
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 23-03-06
Registered User
 
Join Date: Mar 2005
Posts: 222
Thanks: 0
Thanked 0 Times in 0 Posts
stevebrowne is an unknown quantity at this point
Personally I hate using these user controls, as you lose a certain amount of control. I set up as eg:

In ASPX file
<div id="UserName" name="UserName2" runat="server"></div>
<div id="InBox" name="UserName2" runat="server"></div>


Then in my code behind I would have:

public class _default : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlGenericControl UserName;
protected System.Web.UI.HtmlControls.HtmlGenericControl InBox;

private void Page_Load(object sender, System.EventArgs e)
{

//.. do DB query
UserName.InnerHTML = "whatever from DB";
InBox.InnerHTML = "whatever from DB";

// Can now squirt my DB data into anything else on the page as well, without doing another query
}
}
__________________
Steve
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 27-03-06
Registered User
 
Join Date: Sep 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
monkeyboy is an unknown quantity at this point
I'd suggest creating some public properties in the user control and access them from the base page. If you want to isolate the usercontrol from outside changes make the property read only.

I don't know what language you're using so if it's not VB.NET and you don't understand it let me know and I'll translate.

In your usercontrol

Code:
'Username
Public ReadOnly Property TheUsername() As String
    Get
        Return Username.Text
    End Get
End Property

'InBox
Public ReadOnly Property TheInBox() As String
    Get
        Return InBox.Text
    End Get
End Property
Then in your base page you can do this (I've assumed the control ID is MyControl)

Code:
        Dim strUsername As String = Me.MyControl.TheUsername
        Dim strInBox As String = Me.MyControl.TheInBox

        'Now do what ever you want
        LocalLabel.Text = strUsername & " " & strInBox
Any problems let me know.
__________________
Prezzybox.com home of the gift wizard
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 28-03-06
uklejon's Avatar
Registered User
 
Join Date: Aug 2003
Location: Shropshire
Posts: 815
Thanks: 0
Thanked 0 Times in 0 Posts
uklejon is an unknown quantity at this point
Thanks for the help, Jons looking at it now.

Carol
__________________
Jon

UK Link Exchange - Find Link Exchange Partners
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Any ASP.net Security Experts Out There? accelerator Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 5 12-02-06 01:55 PM
learning asp php getvisible Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 5 03-11-03 11:37 AM


Affiliate Marketing RSS Feeds - Contact Us - Affiliate Marketing - Archive - Privacy Statement - Top

Content Relevant URLs by vBSEO 3.2.0 RC7