G
GVaught
PatrioticsignI have an aspx page that references a user-control called connect-strings.ascx. This user control uses connections to various databases. Below is the part I am using.
'declared at the top
<%@Control Language="VB" %> ' declare user control
Public ReadOnly Property SQLConnectionString() As String
Get
'*****************************************************************
Return "server=(local);initial catalog=choice;Connection Timeout=20;Integrated Security=SSPI" '*****************************************************************
End Get
End Property
I did have my Page_Load within my aspx page, which worked fine. However, I decided I wanted to move the info to my code-behind file. I pretty much have everything else defined within my code-behind page except this one line of code:
Dim strConnect As String = New ctlConnectStrings.SQLConnectionString 'problem is underllined
In my declarations I've tried many things. I've reviewed my own ASP.Net book on User Controls, My help within VS.Net 2003 to no avail. This is what I have so far:
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data.SqlClient
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.UserControl
Imports System.Data
Public Class WebOrder
Inherits System.Web.UI.Page
Protected WithEvents ddlClients As System.Web.UI.WebControls.DropDownList
Protected WithEvents dgrClients As System.Web.UI.WebControls.DataGrid
Protected WithEvents outError As System.Web.UI.HtmlControls.HtmlGenericControl
Protected WithEvents msgHello As System.Web.UI.HtmlControls.HtmlGenericControl
Protected WithEvents SqlConnection As System.Data.SqlClient.SqlConnection
'Here I've tried the following:
Protected WithEvents ctlConnectStrings AS System.Web.UI.UserControl
I also tried writing a separate new Class and referencing the Inherits UserControl and then I wasn't sure what to enter after that and the End Class statement. I did add the appropriate references inside the connect-strings.ascx @control statement.
Inside my aspx page I have these referenced entries. However, they were there mainly because of the Page_Load code.
<%@ Register TagPrefix="wrox" TagName="connect" src="connect-strings.ascx" %>
<wrox:connect id="ctlConnectStrings" runat="server">
I seem not to find the magic formula for this one line in the code-behind page.
'Code-behind file called WebOrder.aspx.vb
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'see if the user has been authenticated
If User.Identity.IsAuthenticated Then
'display the properties
msgHello.InnerHtml = "End of Deliveries for <b>" & User.Identity.Name & "</b><br />"
Else
msgHello.InnerHtml = "I'm sorry, you were not authenticated"
End If
If Not IsPostBack Then
Dim strConnect As String = New ctlConnectStrings.SQLConnectionString 'problem underlined
Dim objConnect As New SqlConnection(strConnect)
Dim cmd As SqlCommand
objConnect.Open()
cmd = New SqlCommand("select * from tblClientsSub WHERE Account='" & User.Identity.Name & "'", objConnect)
ddlClients.DataSource = cmd.ExecuteReader()
ddlClients.DataTextField = "ClientName"
ddlClients.DataValueField = "ClientSubCtr"
ddlClients.DataBind()
objConnect.Close()
End If
End Sub
HELP!
'declared at the top
<%@Control Language="VB" %> ' declare user control
Public ReadOnly Property SQLConnectionString() As String
Get
'*****************************************************************
Return "server=(local);initial catalog=choice;Connection Timeout=20;Integrated Security=SSPI" '*****************************************************************
End Get
End Property
I did have my Page_Load within my aspx page, which worked fine. However, I decided I wanted to move the info to my code-behind file. I pretty much have everything else defined within my code-behind page except this one line of code:
Dim strConnect As String = New ctlConnectStrings.SQLConnectionString 'problem is underllined
In my declarations I've tried many things. I've reviewed my own ASP.Net book on User Controls, My help within VS.Net 2003 to no avail. This is what I have so far:
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data.SqlClient
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.UserControl
Imports System.Data
Public Class WebOrder
Inherits System.Web.UI.Page
Protected WithEvents ddlClients As System.Web.UI.WebControls.DropDownList
Protected WithEvents dgrClients As System.Web.UI.WebControls.DataGrid
Protected WithEvents outError As System.Web.UI.HtmlControls.HtmlGenericControl
Protected WithEvents msgHello As System.Web.UI.HtmlControls.HtmlGenericControl
Protected WithEvents SqlConnection As System.Data.SqlClient.SqlConnection
'Here I've tried the following:
Protected WithEvents ctlConnectStrings AS System.Web.UI.UserControl
I also tried writing a separate new Class and referencing the Inherits UserControl and then I wasn't sure what to enter after that and the End Class statement. I did add the appropriate references inside the connect-strings.ascx @control statement.
Inside my aspx page I have these referenced entries. However, they were there mainly because of the Page_Load code.
<%@ Register TagPrefix="wrox" TagName="connect" src="connect-strings.ascx" %>
<wrox:connect id="ctlConnectStrings" runat="server">
I seem not to find the magic formula for this one line in the code-behind page.
'Code-behind file called WebOrder.aspx.vb
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'see if the user has been authenticated
If User.Identity.IsAuthenticated Then
'display the properties
msgHello.InnerHtml = "End of Deliveries for <b>" & User.Identity.Name & "</b><br />"
Else
msgHello.InnerHtml = "I'm sorry, you were not authenticated"
End If
If Not IsPostBack Then
Dim strConnect As String = New ctlConnectStrings.SQLConnectionString 'problem underlined
Dim objConnect As New SqlConnection(strConnect)
Dim cmd As SqlCommand
objConnect.Open()
cmd = New SqlCommand("select * from tblClientsSub WHERE Account='" & User.Identity.Name & "'", objConnect)
ddlClients.DataSource = cmd.ExecuteReader()
ddlClients.DataTextField = "ClientName"
ddlClients.DataValueField = "ClientSubCtr"
ddlClients.DataBind()
objConnect.Close()
End If
End Sub
HELP!