problem with user control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mad Scientist

    #1

    problem with user control

    I am having problems setting a asp user control's property from code.


    I have an asp.net page and have a user control "page_foote r" which has
    a property sFooterText. Here is the control:

    <%@ Control Language="vb" AutoEventWireup ="false"
    Codebehind="pag e_footer.ascx.v b" Inherits="Site1 .page_footer"
    TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5" %>
    <script language="VB" runat="server">
    Public sFooterText As String = ""
    </script>
    <table border="0" width="100%" cellSpacing="0" cellPadding="0" >
    <tr>
    <td align="right">< font
    class="copy"><% =sFooterText%></font>&nbsp;&nbs p;&nbsp;</td>
    </tr>
    </table>


    The control is defined at the top of my aspx page as so:

    <%@ Register TagPrefix="site 1" TagName="page_f ooter"
    Src="page_foote r.ascx" %>



    Everything works great when i set the property explicitly on the page,
    such as:

    <site1:page_foo ter id="page_footer _1" runat="server"
    sFooterText="Co pyright 2004"></site1:page_foot er><br>



    However if i try to set it from codebehind's Page Load with a line
    such as:

    page_footer_1.s FooterText = "Copyright 2004"

    the "page_foote r_1" is underlined in blue, with a message "Name
    'page_footer_1 is not declared."



    Help me, Obi Wan.
  • Mad Scientist

    #2
    Re: problem with user control

    In case anyone else has this problem, I found out what was wrong.

    1. in the codebehind of the aspx page that includes the control,
    before pageinit, i needed to (manually) add:

    Protected WithEvents page_footer_1 As site1.page_foot er

    2. in the user control ascx itself, you can't put the property
    declaration in a <script> tag. WRONG:

    <script language="VB" runat="server">
    Public sFooterText As String = ""
    </script>

    instead, it has to go in the code behind, above Private Sub Page_Load.
    RIGHT:

    Public sFooterText As String = ""

    Comment

    Working...