Re: UserControl Probelm

Discussion in 'ASP .Net' started by Davide Vernole [MVP], Sep 8, 2004.

  1. Sunil Sabir <> typed:
    > Dear All,
    >
    > Actually I have a user control which has nine hyperlinks.What I want
    > to do is that
    > when I add this user control in an .aspx file. It should change the
    > color of the first
    > hyperlink to BLACK. Below is the code:
    >
    > In the User Control Layout.ascx
    >
    > <%@ Register TagPrefix="uc1" TagName="Layout" Src="Layout.ascx" %>
    >
    > Public Value As System.Drawing.Color
    > Public Property valr1Color() As System.Drawing.Color
    >
    > Get
    >
    > Return valr1.ForeColor
    >
    > End Get
    >
    > Set(ByVal Value As System.Drawing.Color)
    >
    >
    > valr1.ForeColor = Value
    > End Set
    >
    > End Property
    >
    > In the WebForm.aspx:
    >
    > Public ctlcontrol As Control
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    >
    > ctlcontrol = LoadControl("Layout.ascx")
    >
    > CType(ctlcontrol, Layout).valr1Color =
    > System.Drawing.Color.Black Me.Controls.Add(ctlcontrol)
    >
    > The problem is that its not changing its color to black in the LOAD
    > event of aspx file.
    >
    > Any help much appreciated.
    >
    > cheers,
    > Sunil Sabir


    I suggest to change approach. Why don't you use a CssClass to change color ?
    You could use a Css sytelsheet file in your web application and than you
    create a class style for the first link.

    Change the property in this way:

    Public Value As String
    Public Property valr1Css() As String
    Get
    Return valr1.CssClass
    End Get
    Set(ByVal Value As String)
    valr1.CssClass = Value
    End Set

    End Property

    and the Page_load like this:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    ctlcontrol = LoadControl("Layout.ascx")
    CType(ctlcontrol, Layout).valr1Css = "myCssClass"
    End Sub


    --
    Davide Vernole
    MVP ASP/ASP.NET
    Microsoft Certified Solution Developer
     
    Davide Vernole [MVP], Sep 8, 2004
    #1
    1. Advertising

  2. Sunil Sabir <> typed:
    > Dear sir,
    >
    > Thanks for your prompt reply. Is it not possible with this
    > approach.Why can't I achieve my task with this code.
    >
    > Any help much appreciated.
    >
    > Cheers,
    > Sunil Sabir
    >



    To tell the truth you can set the ForeColor proprerty and it work (I just
    test it !). I suggest the other approach because I think that the graphical
    style, in a site, it must be set using CSS Stylesheet and not with inline
    style or by code.

    I tried a simple code:

    //C#
    this.lnkTest.ForeColor = System.Drawing.Color.DarkSalmon;

    and it has worked has expected.

    So I suggest you to verify, step by step, your code in debug mode to verify
    if you set this property really.

    --
    Davide Vernole
    MVP ASP/ASP.NET
    Microsoft Certified Solution Developer
     
    Davide Vernole [MVP], Sep 9, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    1,064
    David Binnie
    Mar 17, 2006
  2. Grey
    Replies:
    0
    Views:
    318
  3. Benjamin Bittner

    Probelm with embed server controls

    Benjamin Bittner, Jul 7, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    2,586
    Benjamin Bittner
    Jul 7, 2004
  4. Mohamed Zaki

    Dropdown viewstate probelm

    Mohamed Zaki, Jul 13, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    423
    Mohamed Zaki
    Jul 13, 2004
  5. =?Utf-8?B?VGltOjouLg==?=

    Large File Upload Probelm...

    =?Utf-8?B?VGltOjouLg==?=, May 18, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    597
    =?Utf-8?B?VGltOjouLg==?=
    May 18, 2005
Loading...

Share This Page