Not able to declare variables in custom user controls

Discussion in 'ASP .Net' started by stevong, Jul 19, 2007.

  1. stevong

    stevong Guest

    Hi,

    I've a custom user control:

    'user1.ascx

    <script language="VB" runat="server">
    Public str1 as string
    Dim conn as System.Data.SqlClient ' But this line hits and error.
    What should I do?
    </script>
    Hello World

    I will hit compilation error. What should be the next step? Also, how
    do I use custom namespaces in a custom control?

    Please advise! Thanks!
    stevong, Jul 19, 2007
    #1
    1. Advertising

  2. stevong

    David Wier Guest

    This statement:
    Dim conn as System.Data.SqlClient
    is not a full statement - I'm assuming you're wanting to instantiate a
    Connection - - which would be more like:

    Dim connAs New
    SqlConnection(ConfigurationManager.ConnectionStrings("YourconnString").ConnectionString)

    Import your namespace (System.Data.SqlClient )
    --
    David Wier
    MVP/ASPInsider
    http://aspnet101.com
    http://iWritePro.com



    "stevong" <> wrote in message
    news:...
    > Hi,
    >
    > I've a custom user control:
    >
    > 'user1.ascx
    >
    > <script language="VB" runat="server">
    > Public str1 as string
    > Dim conn as System.Data.SqlClient ' But this line hits and error.
    > What should I do?
    > </script>
    > Hello World
    >
    > I will hit compilation error. What should be the next step? Also, how
    > do I use custom namespaces in a custom control?
    >
    > Please advise! Thanks!
    >
    David Wier, Jul 19, 2007
    #2
    1. Advertising

  3. stevong

    bruce barker Guest

    only methods are allowed in a server script block. to declare var use

    <%
    Public str1 as string
    Dim conn as System.Data.SqlClient ' But this line hits and error.
    %>

    but method def are not allowed here.

    -- bruce (sqlwork.com)

    stevong wrote:
    > Hi,
    >
    > I've a custom user control:
    >
    > 'user1.ascx
    >
    > <script language="VB" runat="server">
    > Public str1 as string
    > Dim conn as System.Data.SqlClient ' But this line hits and error.
    > What should I do?
    > </script>
    > Hello World
    >
    > I will hit compilation error. What should be the next step? Also, how
    > do I use custom namespaces in a custom control?
    >
    > Please advise! Thanks!
    >
    bruce barker, Jul 19, 2007
    #3
  4. stevong,

    You need to import the correct namespace:
    <%@ Import Namespace="System.Data.SqlClient" %>

    You can import custom namespaces the same way

    "stevong" wrote:

    > Hi,
    >
    > I've a custom user control:
    >
    > 'user1.ascx
    >
    > <script language="VB" runat="server">
    > Public str1 as string
    > Dim conn as System.Data.SqlClient ' But this line hits and error.
    > What should I do?
    > </script>
    > Hello World
    >
    > I will hit compilation error. What should be the next step? Also, how
    > do I use custom namespaces in a custom control?
    >
    > Please advise! Thanks!
    >
    >
    =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=, Jul 20, 2007
    #4
    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. rodchar
    Replies:
    0
    Views:
    392
    rodchar
    Nov 26, 2007
  2. Replies:
    4
    Views:
    488
    Mike Treseler
    May 12, 2008
  3. Yuri Vanzine

    User Controls Inherited from a Custom Control share variables?

    Yuri Vanzine, Jul 2, 2004, in forum: ASP .Net Building Controls
    Replies:
    3
    Views:
    231
    Yuri Vanzine
    Jul 2, 2004
  4. Brent
    Replies:
    0
    Views:
    117
    Brent
    Dec 26, 2003
  5. sed_y
    Replies:
    0
    Views:
    1,011
    sed_y
    Feb 15, 2012
Loading...

Share This Page