Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programmatically Declare User Control 1

Status
Not open for further replies.

figler

Programmer
Dec 26, 2001
155
US
I'm struggling, trying to declare a user control in code. ASP.NET seems to accept the declaration, but won't let me access any methods or properties of the object.

For example,
Code:
<%@ Register TagPrefix=&quot;uc0&quot; TagName=&quot;addminiagenda&quot; Src=&quot;addminiagenda.ascx&quot; %>
followed by
Code:
dim cl as new addminiagenda
cl.memberid = e.commandargument.tostring

raises the following error:
'memberid' is not a member of 'ASP.addminiagenda'.

ANY IDEAS??? thanks! -brad
 
First, you need to check to make sure that your namespaces are in order... are you positive that the declaration line is instantiating the proper object?

After that, kill the <%@ Register %> directive... if you're adding the control via code, you don't need it.

You will also need to call upon the page's LoadControl method in order to properly instantiate the object. Consider the following:
Code:
dim cl as new addminiagenda 'assuming this is the proper declaration
cl = CType(LoadControl(&quot;addminiagenda.ascx&quot;),addminiagenda)
cl.memberid = e.CommandArgument.ToString()
Out of curiosity, what comes up in intellisense when you type:
cl.

???

-paul

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
I'm using &quot;Web Matrix&quot; from -- no intellisense.

Not sure i understand your point about the namespace... addminiagenda.ascx is a file in the same directory as the page that this code is running in. I don't know how namespaces apply to user controls...

Tried your suggestion, and I get the exact same error I was getting before. Sounds like you're on the right track with namespaces -- can you explain how they apply to user controls? Thanks. -Brad
 
If it's right there in the same directory, then assuming you haven't monkeyed with namespaces, then it is not an issue (and it appears as though you haven't).

Can I see the code for your usercontrol (trim it down if need be, but if it's not too long, let's just see it all)?

-paul

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
I've stripped down the code until I get this problem fixed, but here's what I have been using for addminiagenda.ascx:
Code:
<%@ Control Language=&quot;VB&quot; %>
<%@ import Namespace=&quot;system.data&quot; %>
<%@ import Namespace=&quot;system.data.oledb&quot; %>
<script runat=&quot;server&quot;>
dim intmemberid as integer
Public Property memberid() As integer
   Get
      Return intmemberid
   End Get
   Set(ByVal Value As integer)
      intmemberid = Value
   End Set
End Property
</script>
<table>
    <tbody>
        <tr>
            <td>
                Meeting Date:</td>
            <td>
                <asp:dropdownlist id=&quot;dddates&quot; runat=&quot;server&quot;></asp:dropdownlist>
            </td>
        </tr>
        <tr>
            <td valign=&quot;top&quot;>
                Agenda:</td>
            <td>
                <asp:textbox id=&quot;tbminiagenda&quot; runat=&quot;server&quot; Width=&quot;400px&quot; Height=&quot;150px&quot;></asp:textbox>
            </td>
        </tr>
    </tbody>
</table>
 
You need to use codebehind in order to get those properties exposed.

Spaghetti code won't cut it for this type of use.

-paul

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top