Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Not able to declare variables in custom user controls (http://www.velocityreviews.com/forums/t523315-not-able-to-declare-variables-in-custom-user-controls.html)

stevong 07-19-2007 04:16 PM

Not able to declare variables in custom user controls
 
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 07-19-2007 04:26 PM

Re: Not able to declare variables in custom user controls
 
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" <stevong@gmail.com> wrote in message
news:1184861761.208465.129240@z28g2000prd.googlegr 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!
>




bruce barker 07-19-2007 07:28 PM

Re: Not able to declare variables in custom user controls
 
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!
>


=?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?= 07-20-2007 02:48 AM

RE: Not able to declare variables in custom user controls
 
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!
>
>



All times are GMT. The time now is 08:31 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.