我必须使用ASP.NET 2.0天编写的旧用户控件。该控件在ASP.NET 2.0环境中运行良好,但当控件与asp.net 4.0一起使用时,它将停止工作。
以下是用户控件的代码:
<%@ Control Language="VB" Inherits="ControlDb" Src="../Bin/ControlDb.vb"%>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Web" %>
<%@ import Namespace="System.Web.UI" %>
<%@ import Namespace="System.Web.UI.WebControls" %>
<%@ import Namespace="System.Web.UI.HtmlControls" %>
<%@ import Namespace="System.Data.OleDb" %>
<%@ import Namespace="System.Configuration" %>
<script runat="server">
' Public isEditable as Boolean
Public Class CommonDb
Inherits System.Web.UI.Page
Dim ConnectionString As String = "<ConnectionString>"
Public Property dbConnection() As String
Get
Return ConnectionString
End Get
Set(ByVal Value As String)
ConnectionString = Value
End Set
End Property
Public Function Execute_GetID(ByVal strSQL As String) As Long
Dim dbConn As New OleDbConnection(ConnectionString)
Dim dbComm1 As New OleDbCommand(strSQL, dbConn)
Dim dbComm2 As New OleDbCommand("SELECT @@IDENTITY", dbConn)
dbConn.Open()
dbComm1.ExecuteNonQuery()
Dim id As Long = CLng(dbComm2.ExecuteScalar())
Return id
End Function
Function Execute(ByVal strSQL As String) As Integer
Dim dbConn As New OleDbConnection(ConnectionString)
Dim dbComm As New OleDbCommand(strSQL, dbConn)
Dim rowsAffected As Integer = 0
dbComm.Connection = dbConn
dbConn.Open()
Try
rowsAffected = dbComm.ExecuteNonQuery
Finally
dbConn.Close()
End Try
Return rowsAffected
End Function
Public Function FillData(ByVal strSQL As String) As DataSet
Dim conn As New OleDbConnection(ConnectionString)
Dim adapter As New OleDbDataAdapter
Dim ds As New DataSet
adapter.SelectCommand = New OleDbCommand(strSQL, conn)
adapter.Fill(ds)
Return ds
End Function
End Class
Private Cdb as new ControlDb()
Private dtR as DataTable
Private resourceIds as DataRow()
Sub Page_Load(Src As Object, E As EventArgs)
End Sub
Public Sub setData()
dtR = Cdb.FillData("SELECT resourceid FROM VEJLEDNING_RESOURCE WHERE centerid = '" & CenterId & "' AND date='" & DateTime & "' ORDER BY resourceid;").tables(0)
if dtR.rows.count > 0 then
Dim dtB as DataTable = Cdb.FillData("SELECT Count(resourceid) FROM VEJLEDNING_BOOKING WHERE resourceid='" & dtR.rows(0)("resourceid") & "'").tables(0)
RBtn.text = FormatDateTime(DateTime,vbShorttime) & "(" & dtR.rows.count & "/" & dtB.rows(0)(0) & ")"
RemBtn.Visible=true
CType(Page.FindControl("IntervalList"),DropDownList).Enabled=false
If dtB.rows(0)(0) >= dtR.rows.count
RBtnClass = "BookingBusyEdit"
else
RBtnClass = "BookingFree"
end if
else
RBtn.text = FormatDateTime(DateTime,vbShorttime) & "(0/0)"
RBtnClass = "BookingNormalEdit"
RemBtn.Visible=false
end if
End Sub
Public ReadOnly Property AddBtnId As Button
Get
Return AddBtn
End Get
End Property
Public ReadOnly Property RBtnId As Button
Get
Return RBtn
End Get
End Property
Public ReadOnly Property RemBtnId As Button
Get
Return RemBtn
End Get
End Property
Public Property Text As String
Get
Return RBtn.text
End Get
Set
RBtn.text = Value
End Set
End Property
Public Property DateTime As String
Get
Return ViewState("time")
End Get
Set
ViewState("time") = Value
End Set
End Property
Public Property CenterId As String
Get
Return ViewState("centerid")
End Get
Set
ViewState("centerid") = Value
End Set
End Property
Public Property isEditable As Boolean
Get
Return ViewState("isEditable")
End Get
Set
ViewState("isEditable") = Value
End Set
End Property
Public Property addBtnClass As String
Get
Return AddBtn.CssClass
End Get
Set
AddBtn.CssClass = Value
End Set
End Property
Public Property RBtnClass As String
Get
Return RBtn.CssClass
End Get
Set
RBtn.CssClass = Value
End Set
End Property
Public Property RemBtnClass As String
Get
Return RemBtn.CssClass
End Get
Set
RemBtn.CssClass = Value
End Set
End Property
Sub AddBtn_Click(sender As Object, e As EventArgs)
NyPost(ViewState("time"))
setData()
End Sub
Sub RBtn_Click(sender As Object, e As EventArgs)
Dim interval as Integer = CType(Page.FindControl("IntervalList"),DropDownList).SelectedItem.Value
if isEditable then
response.redirect("Resource.aspx?id=" & CenterId & "&dtm=" & DateTime & "&interval=" & interval)
else
response.redirect("Booking.aspx?id=" & CenterId & "&dtm=" & DateTime)
end if
End Sub
Sub RemBtn_Click(sender As Object, e As EventArgs)
setData()
Try
Cdb.Execute("DELETE FROM VEJLEDNING_RESOURCE WHERE centerid = '" & CenterId & "' AND date='" & DateTime & "'") ' Ryd
'Cdb.Execute("DELETE FROM VEJLEDNING_RESOURCE WHERE resourceid = '" & dtR.rows (dtR.rows.count-1)("resourceid") & "'") ' Fjern sidste
Catch ex As Exception
End Try
setData()
End Sub
Sub NyPost(dato)
Dim strSQL as string
Dim wn As Integer = DatePart("ww", dato, vbMonday, FirstWeekOfYear.FirstFourDays)
Dim interval as Integer = CType(Page.FindControl("IntervalList"),DropDownList).SelectedItem.Value
If not session("initialer") = nothing then
if wn = 53 then wn = 1
Try
strSQL = "INSERT INTO VEJLEDNING_RESOURCE ("
strSQL = strSQL & "centerid, "
strSQL = strSQL & "week, "
strSQL = strSQL & "interval, "
strSQL = strSQL & "initialer, "
strSQL = strSQL & "date "
strSQL = strSQL & ") "
strSQL = strSQL & "VALUES ("
strSQL = strSQL & "'" & CenterId & "', "
strSQL = strSQL & "'" & wn & "', "
strSQL = strSQL & "'" & interval & "', "
strSQL = strSQL & "'" & session("initialer") & "', "
strSQL = strSQL & "'" & dato & "' "
strSQL = strSQL & ")"
Cdb.Execute(strSQL)
Catch ex As Exception
End Try
End If
End sub
</script>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<asp:Button title="Tilføj ressource" id="AddBtn" onclick="AddBtn_Click" CssClass="BookingFree" Visible="true" Width="14px" runat="server" Text="+"></asp:Button>
</td>
<td width="100">
<asp:Button id="RBtn" onclick="RBtn_Click" Width="100px" runat="server"></asp:Button>
</td>
<td>
<asp:Button title="Slet ressource" id="RemBtn" onclick="RemBtn_Click" CssClass="BookingFree" Visible="true" Width="14px" runat="server" Text="-"></asp:Button>
</td>
</tr>
</table>
以下是使用用户控件的文件中的代码:
<%@ Page Language="vb" Inherits="CommonDb" Src="../bin/CommonDb.vb" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Register TagPrefix="MyControls" TagName="RB" Src="ResourceButton.ascx" %>
<script runat="server">
Dim Cdb As New CommonDb
Dim ResourceDst As DataTable
Dim BookingDst As DataTable
Dim dtmCurrent As Date = Now()
Dim intDatebuff = (Weekday(dtmCurrent, vbMonday) - 1) * -1
Dim dtmMonday As Date = FormatDateTime(DateAdd("d", intDatebuff, dtmCurrent), vbShortDate)
Dim WeekDays As String() = {"Mandag", "Tirsdag", "Onsdag", "Torsdag", "Fredag"}
Dim dtmStart As String = "08:00"
Dim dtmEnd As String = "19:00"
Dim dtmInterval As Integer = 20
Dim BInterval As String() = {"10", "15", "20", "25", "30", "40", "60"}
Dim CenterId As String
Dim cssBtnBar As String
Dim isEditable As Boolean
Dim strOverskrift As String
Dim testYear As String
Sub Page_Load(ByVal Src As Object, ByVal E As EventArgs)
Response.Expires = 0
Response.AppendHeader("Refresh", Convert.ToString((Session.Timeout * 60) + 10) & ";URL=.")
CenterId = Request.QueryString("id")
If CenterId <> "" Or Not Session("initialer") Is Nothing Then
isEditable = (CenterId <> "" And Request.QueryString("admin") <> "" And Not Session("initialer") Is Nothing)
If Not isEditable Then
strOverskrift = "Book en tid : "
cssBtnBar = "display:none;"
Else
strOverskrift = "Læg vejledertider ind (" & Session("initialer") & ")"
End If
If Not IsPostBack Then
VisChatBtn(getChat())
Cdb.Execute("LP_Cleanup_Vejledning_resource") ' 52 uger
If Request.QueryString("dtm") <> "" Then dtmMonday = Request.QueryString("dtm")
ShowPage(dtmMonday)
ViewState("dtmMonday") = dtmMonday
Else
dtmMonday = ViewState("dtmMonday")
End If
Else
Response.Redirect(".")
End If
End Sub
Sub AddControl(ByVal day As String, ByVal e As RepeaterItemEventArgs)
'Dim uc = CType(e.Item.FindControl(day), Web.UI.UserControl)
Dim uc As Web.UI.UserControl = e.Item.FindControl(day)
Dim strTider As String = e.Item.DataItem(day).ToString
Dim ResourceRows As DataRow() = ResourceDst.Select("date='" & strTider & "'")
Dim rc As Integer = ResourceRows.Length
Dim BookingRows As DataRow() = BookingDst.Select("date='" & strTider & "'")
Dim br As Integer = BookingRows.Length
If isEditable Then
uc.RBtnId.text = FormatDateTime(e.Item.DataItem(day).ToString, vbShortTime) & "(" & rc & "/" & br & ")"
If rc = 0 Then
uc.RemBtnId.Visible = False
uc.RBtnClass = "BookingNormalEdit"
ElseIf br >= rc Then
uc.RBtnClass = "BookingBusyEdit"
Else
uc.RBtnClass = "BookingFree"
End If
Else
uc.RBtnId.text = FormatDateTime(e.Item.DataItem(day).ToString, vbShortTime)
uc.RemBtnId.Visible = False
uc.AddBtnId.Visible = False
If rc = 0 Then
setNormalBooking(uc, FormatDateTime(e.Item.DataItem(day).ToString, vbShortTime))
ElseIf br >= rc Then
uc.RBtnId.Attributes.add("onClick", "this.blur();return false;")
uc.RBtnClass = "BookingBusy"
Else
uc.RBtnClass = "BookingFree"
End If
End If
uc.isEditable = isEditable
uc.DateTime = strTider
uc.CenterId = CenterId
End Sub
以下是错误消息:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30456: 'RBtnId' is not a member of 'System.Web.UI.UserControl'.
Source Error:
Line 209:
Line 210: If isEditable Then
Line 211: uc.RBtnId.text = FormatDateTime(e.Item.DataItem(day).ToString, vbShortTime) & "(" & rc & "/" & br & ")"
Line 212: If rc = 0 Then
Line 213: uc.RemBtnId.Visible = False
Source File: \\Webfilefs\websites\DATAPOOL006\u12jbyv\wwwroot\vejlederbooking\hfvuc.aspx Line: 211
Show Detailed Compiler Output:
Microsoft (R) Visual Basic Compiler version 10.0.30319.233
Copyright (c) Microsoft Corporation. All rights reserved.
\\Webfilefs\websites\DATAPOOL006\u12jbyv\wwwroot\vejlederbooking\hfvuc.aspx(211) : error BC30456: 'RBtnId' is not a member of 'System.Web.UI.UserControl'.
uc.RBtnId.text = FormatDateTime(e.Item.DataItem(day).ToString, vbShortTime) & "(" & rc & "/" & br & ")"
~~~~~~~~~
\\Webfilefs\websites\DATAPOOL006\u12jbyv\wwwroot\vejlederbooking\hfvuc.aspx(213) : error BC30456: 'RemBtnId' is not a member of 'System.Web.UI.UserControl'.
uc.RemBtnId.Visible = False
~~~~~~~~~~~
\\Webfilefs\websites\DATAPOOL006\u12jbyv\wwwroot\vejlederbooking\hfvuc.aspx(214) : error BC30456: 'RBtnClass' is not a member of 'System.Web.UI.UserControl'.
uc.RBtnClass = "BookingNormalEdit"
~~~~~~~~~~~~
\\Webfilefs\websites\DATAPOOL006\u12jbyv\wwwroot\vejlederbooking\hfvuc.aspx(216) : error BC30456: 'RBtnClass' is not a member of 'System.Web.UI.UserControl'.
uc.RBtnClass = "BookingBusyEdit"
~~~~~~~~~~~~
\\Webfilefs\websites\DATAPOOL006\u12jbyv\wwwroot\vejlederbooking\hfvuc.aspx(218) : error BC30456: 'RBtnClass' is not a member of 'System.Web.UI.UserControl'.
uc.RBtnClass = "BookingFree"
~~~~~~~~~~~~
\\Webfilefs\websites\DATAPOOL006\u12jbyv\wwwroot\vejlederbooking\hfvuc.aspx(221) : error BC30456: 'RBtnId' is not a member of 'System.Web.UI.UserControl'.
uc.RBtnId.text = FormatDateTime(e.Item.DataItem(day).ToString, vbShortTime)
~~~~~~~~~
\\Webfilefs\websites\DATAPOOL006\u12jbyv\wwwroot\vejlederbooking\hfvuc.aspx(222) : error BC30456: 'RemBtnId' is not a member of 'System.Web.UI.UserControl'.
uc.RemBtnId.Visible = False
~~~~~~~~~~~
\\Webfilefs\websites\DATAPOOL006\u12jbyv\wwwroot\vejlederbooking\hfvuc.aspx(223) : error BC30456: 'AddBtnId' is not a member of 'System.Web.UI.UserControl'.
uc.AddBtnId.Visible = False
~~~~~~~~~~~
\\Webfilefs\websites\DATAPOOL006\u12jbyv\wwwroot\vejlederbooking\hfvuc.aspx(227) : error BC30456: 'RBtnId' is not a member of 'System.Web.UI.UserControl'.
uc.RBtnId.Attributes.add("onClick", "this.blur();return false;")
~~~~~~~~~
\\Webfilefs\websites\DATAPOOL006\u12jbyv\wwwroot\vejlederbooking\hfvuc.aspx(228) : error BC30456: 'RBtnClass' is not a member of 'System.Web.UI.UserControl'.
uc.RBtnClass = "BookingBusy"
~~~~~~~~~~~~
\\Webfilefs\websites\DATAPOOL006\u12jbyv\wwwroot\vejlederbooking\hfvuc.aspx(230) : error BC30456: 'RBtnClass' is not a member of 'System.Web.UI.UserControl'.
uc.RBtnClass = "BookingFree"
~~~~~~~~~~~~
\\Webfilefs\websites\DATAPOOL006\u12jbyv\wwwroot\vejlederbooking\hfvuc.aspx(234) : error BC30456: 'isEditable' is not a member of 'System.Web.UI.UserControl'.
uc.isEditable = isEditable
~~~~~~~~~~~~~
\\Webfilefs\websites\DATAPOOL006\u12jbyv\wwwroot\vejlederbooking\hfvuc.aspx(235) : error BC30456: 'DateTime' is not a member of 'System.Web.UI.UserControl'.
uc.DateTime = strTider
~~~~~~~~~~~
\\Webfilefs\websites\DATAPOOL006\u12jbyv\wwwroot\vejlederbooking\hfvuc.aspx(236) : error BC30456: 'CenterId' is not a member of 'System.Web.UI.UserControl'.
uc.CenterId = CenterId
~~~~~~~~~~~
\\Webfilefs\websites\DATAPOOL006\u12jbyv\wwwroot\vejlederbooking\hfvuc.aspx(405) : warning BC40004: WithEvents variable 'header' conflicts with property 'header' in the base class 'Page' and should be declared 'Shadows'.
Protected WithEvents header As Global.System.Web.UI.WebControls.Literal
如何在4.0下使用此控件?
答案 0 :(得分:0)
我认为WithEvents variable 'header' conflicts with property 'header' in the base class 'Page' and should be declared 'Shadows'.
正在制造问题。尝试解决此错误,看看会发生什么。
答案 1 :(得分:0)
我有一些旧的UserControls在调试模式下工作正常,但是当我尝试发布网站时,我收到了你收到的相同错误,我为控件定义的属性是“不是System.Web的成员.UI.WebControl“。
我认为在UserControl顶部的块中将属性声明为“Public”就足够了。但是,似乎aspnet_compiler工作的方式导致它在我尝试发布站点时无法识别此属性。我没有做过任何挖掘,以找出它为什么不起作用(截止日期,你知道)。如果有人能解释这种行为,我很想听听其背后的原因!
修复?我最终将用户控件的所有代码移动到代码隐藏文件中,而不是将其包含在控件本身顶部的标记中。一旦我这样做,网站编译和发布没有任何错误。