Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Not able to declare variables in custom user controls

Reply
Thread Tools

Not able to declare variables in custom user controls

 
 
stevong
Guest
Posts: n/a
 
      07-19-2007
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!

 
Reply With Quote
 
 
 
 
David Wier
Guest
Posts: n/a
 
      07-19-2007
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.ConnectionStrin gs("YourconnString").ConnectionString)

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



"stevong" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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!
>



 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      07-19-2007
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!
>

 
Reply With Quote
 
=?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=
Guest
Posts: n/a
 
      07-20-2007
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!
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Not able to display color in excel not able to display color in excel using xml sed_y XML 0 02-15-2012 09:46 PM
databound custom controls vs composite databound custom controls rodchar ASP .Net 0 11-26-2007 03:51 PM
User Controls Inherited from a Custom Control share variables? Yuri Vanzine ASP .Net Building Controls 3 07-02-2004 07:55 PM
What's the best way to declare a lot of page level variables when your page is broken up into user controls? Brent ASP .Net Web Controls 0 12-26-2003 12:47 AM
IntelliSense on Web User Controls and Web Custom Controls Axel Dahmen ASP .Net 1 11-12-2003 06:12 AM



Advertisments