|
 |
aspx_beginners thread: Regarding usercontrol
Message #1 by "Shekhar Kulkarni" <shekhar@a...> on Wed, 8 Jan 2003 11:47:03
|
|
Hi All,
I am new to .NET i have created usercontrol for connection to db which is
as follows:
Imports System
Imports System.Web.UI
Public MustInherit Class connectionstring
Inherits System.Web.UI.UserControl
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Public ReadOnly Property OLEDBConnString() As String
Get
Return "Provider=Microsoft.Jet.Oledb.4.0;Data
Source=\html\db\currentstd.mdb"
End Get
End Property
End Class
Now i have to reterive connection string from this control into my aspx
page for that i have ocded login1.aspx page as follows:
<%@ Register TagPrefix="Drucker" TagName="conn"
Src="..\..\connectionstring.ascx" %>
<Drucker:conn id="ConnectString" runat="server" />
and in the code behind page of this (login1.aspx.vb) i.e in Page_Load()
as follows:
Dim strConnect As String
strConnect = ConnectString.OLEDBConnString
But it is giving warning: "Name ConnectString is not declared"
Can anyone help me in this regard i have fade up with this.....
Thanks in advance....
shekhar@a...
Message #2 by "Brian Gaines" <gainesme72@a...> on Wed, 8 Jan 2003 16:40:06
|
|
Wouldn't it be easier to put that logic in the web.config file? Create an
application setting key and reference it in the rest of your application?
Just a thought.
Bg
> Hi All,
I> am new to .NET i have created usercontrol for connection to db which
is
a> s follows:
I> mports System
I> mports System.Web.UI
P> ublic MustInherit Class connectionstring
> Inherits System.Web.UI.UserControl
> #Region " Web Form Designer Generated Code "
> 'This call is required by the Web Form Designer.
> <System.Diagnostics.DebuggerStepThrough()> Private Sub
I> nitializeComponent()
> End Sub
> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
S> ystem.EventArgs) Handles MyBase.Init
> 'CODEGEN: This method call is required by the Web Form Designer
> 'Do not modify it using the code editor.
> InitializeComponent()
> End Sub
> #End Region
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
S> ystem.EventArgs) Handles MyBase.Load
> 'Put user code to initialize the page here
> End Sub
> Public ReadOnly Property OLEDBConnString() As String
> Get
> Return "Provider=Microsoft.Jet.Oledb.4.0;Data
S> ource=\html\db\currentstd.mdb"
> End Get
> End Property
> End Class
> Now i have to reterive connection string from this control into my aspx
p> age for that i have ocded login1.aspx page as follows:
> <%@ Register TagPrefix="Drucker" TagName="conn"
S> rc="..\..\connectionstring.ascx" %>
> <Drucker:conn id="ConnectString" runat="server" />
a> nd in the code behind page of this (login1.aspx.vb) i.e in Page_Load()
a> s follows:
D> im strConnect As String
s> trConnect = ConnectString.OLEDBConnString
> But it is giving warning: "Name ConnectString is not declared"
> Can anyone help me in this regard i have fade up with this.....
> Thanks in advance....
s> hekhar@a...
Message #3 by "Crystal Lilian" <crystal_lilian@h...> on Wed, 08 Jan 2003 16:32:19 +0000
|
|
>From: "Shekhar Kulkarni"
>Reply-To: "aspx_beginners"
>To: "aspx_beginners"
>Subject: [aspx_beginners] Regarding usercontrol
>Date: Wed, 8 Jan 2003 11:47:03
>
>Hi All,
>I am new to .NET i have created usercontrol for connection to db which is
>as follows:
>Imports System
>Imports System.Web.UI
>Public MustInherit Class connectionstring
> Inherits System.Web.UI.UserControl
>
>#Region " Web Form Designer Generated Code "
>
> 'This call is required by the Web Form Designer.
> Private Sub
>InitializeComponent()
>
> End Sub
>
> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
>System.EventArgs) Handles MyBase.Init
> 'CODEGEN: This method call is required by the Web Form Designer
> 'Do not modify it using the code editor.
> InitializeComponent()
> End Sub
>
>#End Region
>
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
>System.EventArgs) Handles MyBase.Load
> 'Put user code to initialize the page here
> End Sub
> Public ReadOnly Property OLEDBConnString() As String
> Get
> Return "Provider=Microsoft.Jet.Oledb.4.0;Data
>Source=\html\db\currentstd.mdb"
> End Get
> End Property
>
>End Class
>
>Now i have to reterive connection string from this control into my aspx
>page for that i have ocded login1.aspx page as follows:
>
><%@ Register TagPrefix="Drucker" TagName="conn"
>Src="..\..\connectionstring.ascx" %>
>
>
>and in the code behind page of this (login1.aspx.vb) i.e in Page_Load()
>as follows:
>Dim strConnect As String
>strConnect = ConnectString.OLEDBConnString
>
>But it is giving warning: "Name ConnectString is not declared"
>
>Can anyone help me in this regard i have fade up with this.....
>
>Thanks in advance....
>shekhar@a...
>---
The new MSN 8 is here: Try it free* for 2 months
Message #4 by "Patterson, Stephanie L" <stephanie.l.patterson@i...> on Wed, 8 Jan 2003 09:01:41 -0800
|
|
I use web.config for storing my database connection string (SQL not Access,
but you can modify appropriately).
web.config entry:
<appSettings>
<add key="ConnectionStringDev"
value="server=devsys;database=joesdb;Connect Timeout=30" />
<add key="ConnectionStringTest"
value="server=testsys;database=joesdb;Connect Timeout=30" />
<add key="ConnectionStringProd"
value="server=prodsys;database=joesdb;Connect Timeout=30" />
</appSettings>
In the VB code:
Public strServerName As String
Public strConnection As String
strServerName = Request.ServerVariables("SERVER_NAME")
If InStr(LCase(strServerName), "devsys") Then
strConnection
ConfigurationSettings.AppSettings("ConnectionStringDev")
ElseIf InStr(LCase(strServerName), "testsys") Then
strConnection
ConfigurationSettings.AppSettings("ConnectionStringTest")
Else
strConnection
ConfigurationSettings.AppSettings("ConnectionStringProd")
End If
Dim objConnection As New SqlConnection(strConnection)
Hope this helps!
Stephanie
-----Original Message-----
From: Shekhar Kulkarni [mailto:shekhar@a...]
Sent: Wednesday, January 08, 2003 3:47 AM
To: aspx_beginners
Subject: [aspx_beginners] Regarding usercontrol
Hi All,
I am new to .NET i have created usercontrol for connection to db which is
as follows:
Imports System
Imports System.Web.UI
Public MustInherit Class connectionstring
Inherits System.Web.UI.UserControl
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Public ReadOnly Property OLEDBConnString() As String
Get
Return "Provider=Microsoft.Jet.Oledb.4.0;Data
Source=\html\db\currentstd.mdb"
End Get
End Property
End Class
Now i have to reterive connection string from this control into my aspx
page for that i have ocded login1.aspx page as follows:
<%@ Register TagPrefix="Drucker" TagName="conn"
Src="..\..\connectionstring.ascx" %>
<Drucker:conn id="ConnectString" runat="server" />
and in the code behind page of this (login1.aspx.vb) i.e in Page_Load()
as follows:
Dim strConnect As String
strConnect = ConnectString.OLEDBConnString
But it is giving warning: "Name ConnectString is not declared"
Can anyone help me in this regard i have fade up with this.....
Thanks in advance....
shekhar@a...
Message #5 by "Jack" <jdunstan7@h...> on Wed, 8 Jan 2003 12:44:59 -0500
|
|
Crystal,
Your usercontrol class is defined as:
Public MustInherit Class connectionstring
but in your code behind on login1.aspx.vb you have
ConnectString.OLEDBConnString
That should fix the error.
Also what Brian mentioned about putting it the web.config file will also work and is pretty easy. I believe there is a small
perfomance hit when accessing variables in the web.config but not enough to worry about for most applications.
Jack
----- Original Message -----
From: Crystal Lilian
To: aspx_beginners
Sent: Wednesday, January 08, 2003 11:32 AM
Subject: [aspx_beginners] Re: Regarding usercontrol
>From: "Shekhar Kulkarni"
>Reply-To: "aspx_beginners"
>To: "aspx_beginners"
>Subject: [aspx_beginners] Regarding usercontrol
>Date: Wed, 8 Jan 2003 11:47:03
>
>Hi All,
>I am new to .NET i have created usercontrol for connection to db which is
>as follows:
>Imports System
>Imports System.Web.UI
>Public MustInherit Class connectionstring
> Inherits System.Web.UI.UserControl
>
>#Region " Web Form Designer Generated Code "
>
> 'This call is required by the Web Form Designer.
> Private Sub
>InitializeComponent()
>
> End Sub
>
> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
>System.EventArgs) Handles MyBase.Init
> 'CODEGEN: This method call is required by the Web Form Designer
> 'Do not modify it using the code editor.
> InitializeComponent()
> End Sub
>
>#End Region
>
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
>System.EventArgs) Handles MyBase.Load
> 'Put user code to initialize the page here
> End Sub
> Public ReadOnly Property OLEDBConnString() As String
> Get
> Return "Provider=Microsoft.Jet.Oledb.4.0;Data
>Source=\html\db\currentstd.mdb"
> End Get
> End Property
>
>End Class
>
>Now i have to reterive connection string from this control into my aspx
>page for that i have ocded login1.aspx page as follows:
>
><%@ Register TagPrefix="Drucker" TagName="conn"
>Src="..\..\connectionstring.ascx" %>
>
>
>and in the code behind page of this (login1.aspx.vb) i.e in Page_Load()
>as follows:
>Dim strConnect As String
>strConnect = ConnectString.OLEDBConnString
>
>But it is giving warning: "Name ConnectString is not declared"
>
>Can anyone help me in this regard i have fade up with this.....
>
>Thanks in advance....
>shekhar@a...
>---
The new MSN 8 is here: Try it free* for 2 months
Message #6 by "Shekhar Kulkarni" <shekhar@a...> on Thu, 9 Jan 2003 04:04:33
|
|
Hi All,
Thanks for your early reply....it is fine to do it with Web.config but i
have created the usercontrol for learning the things......any usercontrol
i create i have the same problem.....i can't refer to property of
usercontrol....
> Hi All,
I> am new to .NET i have created usercontrol for connection to db which
is
a> s follows:
I> mports System
I> mports System.Web.UI
P> ublic MustInherit Class connectionstring
> Inherits System.Web.UI.UserControl
> #Region " Web Form Designer Generated Code "
> 'This call is required by the Web Form Designer.
> <System.Diagnostics.DebuggerStepThrough()> Private Sub
I> nitializeComponent()
> End Sub
> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
S> ystem.EventArgs) Handles MyBase.Init
> 'CODEGEN: This method call is required by the Web Form Designer
> 'Do not modify it using the code editor.
> InitializeComponent()
> End Sub
> #End Region
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
S> ystem.EventArgs) Handles MyBase.Load
> 'Put user code to initialize the page here
> End Sub
> Public ReadOnly Property OLEDBConnString() As String
> Get
> Return "Provider=Microsoft.Jet.Oledb.4.0;Data
S> ource=\html\db\currentstd.mdb"
> End Get
> End Property
> End Class
> Now i have to reterive connection string from this control into my aspx
p> age for that i have ocded login1.aspx page as follows:
> <%@ Register TagPrefix="Drucker" TagName="conn"
S> rc="..\..\connectionstring.ascx" %>
> <Drucker:conn id="ConnectString" runat="server" />
a> nd in the code behind page of this (login1.aspx.vb) i.e in Page_Load()
a> s follows:
D> im strConnect As String
s> trConnect = ConnectString.OLEDBConnString
> But it is giving warning: "Name ConnectString is not declared"
> Can anyone help me in this regard i have fade up with this.....
> Thanks in advance....
s> hekhar@a...
Message #7 by "Bhagvan Chougule" <bhagvan@a...> on Thu, 9 Jan 2003 05:23:01
|
|
Declare variable you registered i.e. ConnectString as class name
(connectionstring in this case) in login1.aspx.vb. This will solve the
problem.
> Hi All,
I> am new to .NET i have created usercontrol for connection to db which
is
a> s follows:
I> mports System
I> mports System.Web.UI
P> ublic MustInherit Class connectionstring
> Inherits System.Web.UI.UserControl
> #Region " Web Form Designer Generated Code "
> 'This call is required by the Web Form Designer.
> <System.Diagnostics.DebuggerStepThrough()> Private Sub
I> nitializeComponent()
> End Sub
> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
S> ystem.EventArgs) Handles MyBase.Init
> 'CODEGEN: This method call is required by the Web Form Designer
> 'Do not modify it using the code editor.
> InitializeComponent()
> End Sub
> #End Region
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
S> ystem.EventArgs) Handles MyBase.Load
> 'Put user code to initialize the page here
> End Sub
> Public ReadOnly Property OLEDBConnString() As String
> Get
> Return "Provider=Microsoft.Jet.Oledb.4.0;Data
S> ource=\html\db\currentstd.mdb"
> End Get
> End Property
> End Class
> Now i have to reterive connection string from this control into my aspx
p> age for that i have ocded login1.aspx page as follows:
> <%@ Register TagPrefix="Drucker" TagName="conn"
S> rc="..\..\connectionstring.ascx" %>
> <Drucker:conn id="ConnectString" runat="server" />
>and in the code behind page of this (login1.aspx.vb) i.e in Page_Load()
>as follows:
>Dim strConnect As String
>strConnect = ConnectString.OLEDBConnString
> But it is giving warning: "Name ConnectString is not declared"
> Can anyone help me in this regard i have fade up with this.....
> Thanks in advance....
s> hekhar@a...
|
|
 |