System.ArgumentException: String value can not be converted to a date - asp.net

I have a web form that uses an Ajax date calendar. This works fine. The problem that i have is that when i submit my form i get the following message.
'String value can not be converted to a date' .AgendaDate = New SmartDate(txtAgendaDate.Text)
Here is my web form that holds the calendar and the associated text box...
<td>
<asp:TextBox ID="txtAgendaDate" runat="server" ForeColor="Black" ></asp:TextBox>
</td>
<td>
<asp:ImageButton runat="Server" ID="ImageButton1" ImageUrl="~/images/calendarpic.png"
AlternateText="Click here to display calendar" />
<cc1:calendarextender ID="CalendarExtender1" runat="server"
TargetControlID="txtAgendaDate" PopupButtonID="ImageButton1" >
</cc1:calendarextender>
</td>
I have a class with the associated properties on it for the web form. The rest of the fields work and submit data to the database except the textfield for the ajax calendar.
Here is my stripped down version for the code for the class and the txtAgendaDate code...
#Region " Agenda Variables "
'Declare Variables and data types and set default values
Private mAgendaID As Integer = 0
Private mOrganiser As String = ""
Private mMeeting As String = ""
Private mAgendaDate As SmartDate = New SmartDate()
#End Region
#Region " Constructors "
Public Sub New()
End Sub
Public Sub New(ByVal reader As SafeDataReader)
' Public Sub New(ByVal reader As SQLDataReader)
'Combine variables & property types
With reader
mAgendaID = .GetInt32("AgendaID")
mOrganiser = .GetString("Organiser")
mMeeting = .GetString("Meeting")
mAgendaDate = .GetSmartDate("AgendaDate")
End With
End Sub
#End Region
#Region "Properties"
'Define form field properies so that they can be used when adding the data to the database on the add button is pressed.
Public Property AgendaID() As Integer
Get
Return mAgendaID
End Get
Set(ByVal Value As Integer)
mAgendaID = Value
End Set
End Property
Public Property Organiser() As String
Get
Return mOrganiser
End Get
Set(ByVal value As String)
mOrganiser = value
End Set
End Property
Public Property Meeting() As String
Get
Return mMeeting
End Get
Set(ByVal value As String)
mMeeting = value
End Set
End Property
Public Property AgendaDate() As SmartDate
Get
Return mAgendaDate
End Get
Set(ByVal Value As SmartDate)
mAgendaDate = Value
End Set
End Property
#End Region
End Class
Here is my command that looks connects to the DB and at the stored procedure and also has the parameters.
Public Class Agenda_TempDAL
Public Shared Function AddAgenda_Temp(ByVal Agenda_Temp As Agenda_Temp) As Integer
'Declare i as integer as 0
Dim iAgendaID As Integer = 0
'Database conn, this is linked to the web config file .AppSettings
Using dbconnection As New SqlConnection(ConfigurationManager.AppSettings("dbconnection"))
dbconnection.Open()
'Command to state the stored procedure and the name of the stored procedure
Using dbcommand As SqlCommand = dbconnection.CreateCommand
With dbcommand
.CommandType = CommandType.StoredProcedure
.CommandText = "Stored_Proc_Name"
'Create parameter for AgendaID and output
Dim oParam As New SqlParameter
oParam.ParameterName = "#AgendaID"
oParam.Direction = ParameterDirection.Output
oParam.SqlDbType = SqlDbType.Int
'Create parameters for the remaining fields
.Parameters.Add(oParam)
.Parameters.AddWithValue("#Organiser", Agenda_Temp.Organiser)
.Parameters.AddWithValue("#Meeting", Agenda_Temp.Meeting)
.Parameters.AddWithValue("#AgendaDate", Agenda_Temp.AgendaDate.DBValue)
'Simply execute the query
dbcommand.ExecuteNonQuery()
End With
End Using
End Using
'Need to return the agendaID as an integer.
Return iAgendaID
End Function
End Class
And here is the code behind the button ion the web page. This is the page that causes the error based on the property / field. The problem lies on this line...
.AgendaDate = New SmartDate(txtAgendaDate.Text)
The whole code for the button is here...
Protected Sub btnAddAgendaTemplate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddAgendaTemplate.Click
'This works alongside the Class named Agenda_Temp which has the properties and DB connection assigned to it for each web form field.
Dim oAgenda_Temp As New Agenda_Temp
'Within the object Agenda_Temp Class use the properties defined.
'They are required to be defined in the Agenda_Temp/ app code so we can use them within here.
With oAgenda_Temp
.Organiser = txtOrganiser.Text
.Meeting = txtMeeting.Text
.AgendaDate = New SmartDate(txtAgendaDate.Text)
'Within the object Agenda_Temp class use the defined DAL which includes all the DC connect and stored procedures.
oAgenda_Temp.AgendaID = Agenda_TempDAL.AddAgenda_Temp(oAgenda_Temp)
End With
End Sub
End Class
I understand that its telling me that the string value cannot be converted to a date but i don't know hoe to resolve this as i am new to .net 2010?
Any help much appreciated.

Convert the string to a date before newing it:
From MSDN:
string date = "01/08/2008";
DateTime dt = Convert.ToDateTime(date);
Your's would become
DateTime dt = Convert.ToDateTime(txtAgendaDate.Text)
Then pass the date to your SmartDate constructor:
oAgenda_Temp.AgendaDate = new SmartDate(dt)
The final result:
With oAgenda_Temp
.Organiser = txtOrganiser.Text
.Meeting = txtMeeting.Text
.AgendaDate = New SmartDate(Convert.ToDateTime(txtAgendaDate.Text))
'Within the object Agenda_Temp class use the defined DAL which includes all the DC connect and stored procedures.
oAgenda_Temp.AgendaID = Agenda_TempDAL.AddAgenda_Temp(oAgenda_Temp)
End With

As others have pointed out, you need to convert the input value to a DateTime. I don't know what the SmartDate() function is doing, but the error message clearly indicates that the value cannot be converted to a date.
Secondly, I would add some validation to make sure that the input is valid before you submit the page. Use the RequiredFieldValidator and CompareValidator or RegularExpressionValidator:
<asp:TextBox ID="txtDate" runat="server" ... />
<asp:RequiredFieldValidator ID="reqDate" runat="server" ErrorMessage="Required" Display="Dynamic" ControlToValidate="txtDate"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regDate" runat="server" ControlToValidate="txtDate" ErrorMessage="Please enter a valid date in the format (mm/dd/yyyy)" ValidationExpression="^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$"></asp:RegularExpressionValidator>

Related

PreviousPage and control created at run-time

At run-time I add a textbox with
Dim MRNCell As New TableCell
MRNCell.ID = "MRNCell"
Dim txtMRN As New TextBox
txtMRN.ID = "NewMRN"
MRNCell.Controls.Add(txtMRN)
MRNRow.Cells.Add(MRNCell)
I then attempt to access the Text property in a public readonly Property using PreviousPage. Below are three renditions of the Property, none of which works.
Public ReadOnly Property NewMRN() As String
Get
Dim NewMRNNum As TextBox = CType(Me.FindControl("NewMRN"), TextBox)
'NewMRNNum = Nothing
Return NewMRNNum.Text
End Get
End Property
Public ReadOnly Property NewMRN() As String
Get
Dim sNewMRN As String = String.Empty
For Each MyRow As TableRow In MyTable.Rows
For Each MyCell As TableCell In MyRow.Cells
If MyCell.ID = "MRNCell" Then
For Each MyControl As Control In MyCell.Controls
Dim MRNBox As New TextBox
MRNBox = TryCast(MyControl, TextBox)
If Not (MRNBox Is Nothing) Then
sNewMRN = MRNBox.Text
End If
Next
End If
Next
Next
'There is only one TextBox in the table and sNewMRN = ""
Return sNewMRN
End Get
End Property
Public ReadOnly Property NewMRN() As String
Get
'For this one the TextBox is declared Public in the class
'The Text property = ""
Return txtMRN.Text
End Get
End Property
I have two public readonly properties. The first one returns the Text property from a TextBox created in the designer and the other attempts to return the Text property created at run-time. One works and the other either throws an exception or returns an empty string, depending on which of the three methods I use.
If Not PreviousPage Is Nothing Then
'Works
Dim sMessageID As String = PreviousPage.MessageID
'Does not work
Dim sNewMRN As String = PreviousPage.NewMRN
Literal1.Text = "<p>" & sMessageID & "</p><p>" & sNewMRN & "</p>"
End If
So, how can I access the Text property of a Textbox created at run-time, have that value returned in a public readonly property, so I can access it with PreviousPage?
Greg
Once again, writing the question made me think about it enough that I came up with a solution. I add the textbox at design-time and set the visible property to false. Then at run-time I make it visible and add it to the table row cell.
Greg

combining two textbox values

i called a field from mysql into a readonly textarea and i made another textbox to allow users to add fields into the textarea. how do I combine the values from the textbox into the textarea?
an example of what i want to do is:
textarea
15/12: Nothing special today
16/12: another day
17/12: and so on
textbox
this is a new input
Result
15/12: Nothing special today
16/12: another day
17/12: and so on
18/12: this is a new input
The textarea is "log1" and the textbox is "txb1". I'm currently using
log = trim(request.form("log1"))
how do I do something like
log = trim(request.form("log1")) <br> date ": " trim(request.form("txb1"))
assuming date is a string variable, You would want to do the following:
log = trim(request.form("log1")) & "<br>" & [date] & ": " & trim(request.form("txb1"))
also, if date is a DateTime variable, you would want to use date.ToShortDateString() and instead of <br/> i would recommend using Environment.NewLine
and even better, you should use StringBuilder:
Dim SB As New StringBuilder()
SB.AppendLine(trim(request.form("log1")))
SB.AppendLine([date] & ": " & trim(request.form("txb1")))
log = SB.ToString()
UPDATE:
if you want to store the entire log in one record rather than a separate table, you better off saving it as a list of logs into a varbinary(MAX) column.
here is a full example of how to do it:
1. we start by creating a <div> element that will hold our pretty logs and will be handled by the server, and a text box for new logs:
<asp:TextBox ID="txb1" runat="server"></asp:TextBox>
<div id="Text_Div1" runat="server"></div>
2. now in the code behind, we create a class to hold 1 single line of log:
'create a log class and state that it serializable
<Serializable> _
Public Class MyLogRecord
Public Sub New(_msg As String)
[Date] = DateTime.Now
Message = _msg
End Sub
Public Property [Date]() As DateTime
Get
Return m_Date
End Get
Set
m_Date = Value
End Set
End Property
Private m_Date As DateTime
Public Property Message() As [String]
Get
Return m_Message
End Get
Set
m_Message = Value
End Set
End Property
Private m_Message As [String]
Public Function ToText() As String
Return [Date].ToShortDateString() & ": " & Convert.ToString(Message)
End Function
End Class
3. wherever you update the logs, whether its button_click or textbox_keydown, you do the following:
' create a list of logs
Dim MyLogs As List(Of MyLogRecord)
'check if we stored the logs already in the session,
'if yes, retrieve it from the session var,
'if not then create a new one.
If Session("MyLogs") IsNot Nothing Then
MyLogs = DirectCast(Session("MyLogs"), List(Of MyLogRecord))
Else
MyLogs = New List(Of MyLogRecord)()
End If
' create a new log record from the new textbox value
Dim _tempLog As New MyLogRecord(txb1.Text)
'add the new log to the list
MyLogs.Add(_tempLog)
'save it back in a session var:
Session("MyLogs") = MyLogs
4. in the part where you save the logs to the mysql db, you do it this way: first convert the list to a byte array and store it in a varbinary(MAX) column
'create a new binary formatter, include System.Runtime.Serialization.Formatters.Binary;
Dim formatter As New BinaryFormatter()
'create a byte array to store our logs list
Dim _logsBinary As Byte()
'create a memory stream to write the logs list into
Using _logStream As New MemoryStream()
'use the formatter to serialize the list in to an array of bytes
'directly into the memory stream
formatter.Serialize(_logStream, MyLogs)
'dump the memory stream into the byte array
_logsBinary = _logStream.ToArray()
End Using
' ... save the _logsBinary into mysql as a 'varbinary(max)' ...
5. in the place where you retrieve the logs from the mysql db, you de-serialize the byte array back to a logs list:
Dim MyLogs As New List(Of MyLogRecord)()
Dim formatter As New BinaryFormatter()
Using _logStream As New MemoryStream()
_logStream.Write(_logsBinary, 0, _logsBinary.Length)
_logStream.Position = 0
' de-serialize the byte array back into a logs list
MyLogs = DirectCast(formatter.Deserialize(_logStream), List(Of MyLogRecord))
End Using
6. in the place where you write the logs in your page, you do it this way:
Dim SB As New StringBuilder()
' create a temp date to compare against all the records,
' and initialize it with the first value or else you will have
' a orizontal line before the first row
Dim _prevDate As DateTime = MyLogs.First().[Date]
For Each _logRec As MyLogRecord In MyLogs
'take the date of the currently iterrated item and
'compare against the temp date, note that comparing months is not enough,
'month might be same/earlier but year can be higher
Dim _currentDate As DateTime = _logRec.[Date]
If _currentDate.Month > _prevDate.Month OrElse _currentDate.Year > _prevDate.Year Then
'append horizontal line
SB.AppendLine("<hr/>")
'update temp value
_prevDate = _currentDate
End If
'finally append the log: ToText() is the class custom
'function that we created above
SB.AppendLine(_logRec.ToText())
Next
'dump the logs into the server managed div:
Text_Div1.InnerHtml = SB.ToString()

Can't keep running totals - ASP.NET / VB

I have an assignment to create a website that people can use to make dinner reservations. We are using Visual Basic code for the forms. It's supposed to keep running totals of each type of dinner. I'm having trouble getting the running totals to not reset to zero. I have them declared outside of the button click event. Not sure where I went wrong. Here's the code:
Option Strict On
Partial Class _Default
Inherits System.Web.UI.Page
Private Chicken_RT As Integer
Private Rib_RT As Integer
Private Veg_RT As Integer
Protected Sub SubmitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubmitButton.Click
'Variables
Dim DinnerPrice As Integer
Dim RadioSelect As Boolean = True
Dim Tickets As Integer
Dim DinnerType As String
'Parsing
Tickets = Integer.Parse(TicketTextBox.Text)
'Validation / Calculations
If TicketRangeValidator.IsValid And TicketValidator.IsValid Then
If ChickenRadio.Checked = True Then
DinnerPrice = Tickets * 15
Chicken_RT += Tickets
DinnerType = "Chicken"
ElseIf RibRadio.Checked = True Then
DinnerPrice = Tickets * 20
Rib_RT += Tickets
DinnerType = "Rib"
ElseIf VegetarianRadio.Checked = True Then
DinnerPrice = Tickets * 12
Veg_RT += Tickets
DinnerType = "Vegetarian"
Else
RadioErrorLabel.Text = ("Please select a dinner type")
RadioSelect = False
End If
'Display results
If RadioSelect = True Then
If OpenBarCheckBox.Checked = True Then
DinnerPrice += Tickets * 15
OpenBarLabel.Text = "Yes"
Else
OpenBarLabel.Text = "No"
End If
NumberDinnersLabel.Text = Tickets.ToString()
DinnerTypeLabel.Text = DinnerType
TotalCostLabel.Text = DinnerPrice.ToString("C")
TotalChickenLabel.Text = Chicken_RT.ToString()
TotalRibLabel.Text = Rib_RT.ToString()
TotalVegetarianLabel.Text = Veg_RT.ToString()
End If
End If
End Sub
End Class
I have [the running totals] declared outside of the button click event.
Every time you handle an event, you're working with a new instance of your page class.
Understand that, and everything that's happening here should start to make sense to you. You must keep your totals in a place that persists across individual http requests, such as viewstate, the session, the application cache, on the file system, or in a database. Variables in your class to do not persist across individual http requests.
As Joel said, the values will not persist as each HTTP request creates a new instance of your class. The HiddenField Class would suit you nicely in this situation.
First, remove these lines of code:
Private Chicken_RT As Integer
Private Rib_RT As Integer
Private Veg_RT As Integer
Second, put this in your .aspx Markup (nested in the Form tag):
<asp:HiddenField id="Chicken_RT" runat="server" value="0"/>
<asp:HiddenField id="Rib_RT" runat="server" value="0"/>
<asp:HiddenField id="Veg_RT" runat="server" value="0"/>
Finally,
Veg_RT += Tickets
Becomes:
Veg_RT.Value = (CInt(Veg_RT.Value) + Tickets).ToString()
(Repeat for all of your running totals.)
To access your totals you would do:
Dim intVegTotal As Integer = CInt(Veg_RT.Value)
Well, I see you are reading TicketTextBox, but I don't see you assigning it any where. If you don't assign it, won't it's value always be zero?

Stumped With Custom Property on User Control

I have created an ASP.NET usercontrol. When I explicity provide the value for a custom property, the value is passed to the control. However, when I try to use the value from a datasource, the value is not passed to the control.
The user control sits within a FormView. The FormView successfully displays the underlying record. I am attempting to pass to the control a value in a column from the FormView's datasource. This works
<asp:formview .... />
<editTemplate>
<uctrl:DateSelector ID="DateSelector1" runat="server" DateValue="5/30/2011" /><br />
<%#Eval("MilestoneDate")%>
</editTemplate>
</asp:formview>
This does not...
<asp:formview .... />
<editTemplate>
<uctrl:DateSelector ID="DateSelector1" runat="server" DateValue='<%#Eval("MilestoneDate")%>' /><br />
<%#Eval("MilestoneDate")%>
</editTemplate>
</asp:formview>
I have confirmed that MileStoneDate does have a value in it. For whatever the reason, the value is not being passed to the control, however the control does recognize a literal value.
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.UI
Imports System.ComponentModel
Partial Class content_WebUserControl
Inherits System.Web.UI.UserControl
<Bindable(True, BindingDirection.OneWay)>
Public Property DateValue() As String
Get
Return _DateValue
End Get
Set(ByVal value As String)
_DateValue = value
End Set
End Property
Private _DateValue As String
Protected Sub Page_Load() Handles Me.Load
If IsDate(Me.DateValue) Then
Dim NewDate As DateTime = CDate(Me.DateValue)
LabelSelectedDateDisplay.Text = Me.DateValue
LabelSelectedDateDisplay_DayOfWeek.Text = NewDate.ToString("dddd")
TextBoxSelectedDate.Text = Me.DateValue
Else
LabelSelectedDateDisplay.Text = ""
LabelSelectedDateDisplay_DayOfWeek.Text = ""
TextBoxSelectedDate.Text = ""
End If
End Sub
End Class
I was refered to the post at this URL ASP.NET User Control : can't initialize a user control property using Eval("...")
However, based on my understanding of the post, what I have should be working.
You need to use ViewState to persists DateValue between page requests.
Public Property DateValue() As String
Get
IF IsNothing(ViewState("datevalue") Then
return String.Empty
End If
return ViewState("datevalue").ToString()
End Get
Set(ByVal value As String)
ViewState("datevalue")=value
End Set
End Property
Or store value directly to the controls:
Public Property DateValue() As String
Get
Return LabelSelectedDateDisplay.Text
End Get
Set(ByVal value As String)
If IsDate(value) Then
Dim NewDate As DateTime = CDate(value)
LabelSelectedDateDisplay.Text = NewDate
LabelSelectedDateDisplay_DayOfWeek.Text = NewDate.ToString("dddd")
TextBoxSelectedDate.Text = NewDate
Else
LabelSelectedDateDisplay.Text = ""
LabelSelectedDateDisplay_DayOfWeek.Text = ""
TextBoxSelectedDate.Text = ""
End If
End Set
End Property
The problem is that databinding doesn't occur on your formview until after Page.Load, and you are checking the value of the property during that time. If you want the value to be set in Page.Load you need to manually bind using FormView.Databind().
Alternatively, you can change the code you listed in your custom control from handling Page.Load to handle Page.Prerender, if nothing requires that code to execute earlier.
It looks like the issue might be timing/event related.
When you set a property with <%# %>, the value is assigned to the property during the Control's databinding event. If you look for it at Page_Load() time, it won't be there yet.
If you change your code to check the value in the PreRender event, it should be there.

Connect reusable ASP.NET WebControl to a method for loading data

I'm trying to create a control that can extend other webcontrols and set some properties like visible and enabled, based on user permissions.
Here's an example where your user role would need to include the "CanSave" permission:
<asp:Button ID="btn1" runat="server" Text="Save"/>
<myControls:PermissionsExtender runat="server" ControlToSet="btn1" Permission="CanSave"/>
I'm trying to keep this reusable, that's why the PermissionExtender is in a separate project that can not have any dependencies to other projects. To make a decision, the control of course needs to get this info from somewhere else (database or something). I made another control and, using events, the above extender will be set by a master control, so only that needs to know where to look up the information.
The master control now needs to be configured to know where the information about roles and permissions will be coming from. My idea was to have an interface inside the reusable project, and implement that somewhere else, then configure my control to go and find the class that implements the method I need and load it through reflection. But I'm unclear how this could work. I would probably place the master control in the masterpage and supply it a class name like PermissionClass="SecurityLibrary.PermissionsClass". Kinda like ObjectDatasource does it, but other suggestions are welcome.
The method signature would be like:
bool HasPermission(string permission)
It would know the current users role and using that combination, looks up if the role includes the permission.
How can I wire up a call from the control to a method inside my main project that can supply the necessary information without making them dependent.
I think I've got something that will work for you (tested fine for me but I may have misunderstood part of what you were looking for). With this implementation the asp.net designer code will look like this:
<web:PermissionMasterControl runat="server" ID="masterController" PermissionClass="SecurityLibrary.RandomPermissionClass" />
<asp:Button ID="btnSave" runat="server" Text="save" />
<web:PermissionExtender runat="server" ControlToSet="btnSave" Permission="CanSave" MasterControllerID="masterController" />
Now for the SecurityLibrary. Pretty straight forward, I included a simple "RandomPermissionClass" that randomly returns true/false.
Namespace SecurityLibrary
Public MustInherit Class PermissionClass
Public MustOverride Function HasPermission(ByVal permission As String) As Boolean
End Class
Public Class RandomPermissionClass
Inherits PermissionClass
Private rand As New Random()
Public Overrides Function HasPermission(permission As String) As Boolean
Return If(rand.Next(2) = 0, False, True)
End Function
End Class
End Namespace
Now we have the "myControls" library, which contains no references to SecurityLibrary. I created two controls and a delegate. The controls are "PermissionMasterControl" and "PermissionExtender". The delegate is what is used to actually perform the check against the reflected object.
Namespace myControls
Public Delegate Function HasPermissionDelegate(ByVal permission As String) As Boolean
Public Class PermissionMasterControl
Inherits System.Web.UI.Control
Public Property PermissionClass As String
Get
Return If(ViewState("PermissionClass") Is Nothing, "", ViewState("PermissionClass").ToString())
End Get
Set(value As String)
ViewState("PermissionClass") = value
End Set
End Property
Private ReadOnly Property PermissionDelegate As HasPermissionDelegate
Get
If _permissionDel Is Nothing Then
If Not String.IsNullOrEmpty(PermissionClass) Then
Dim t = Type.GetType(PermissionClass, False)
If t IsNot Nothing Then
_permissionObj = Activator.CreateInstance(t)
Dim mi As MethodInfo = _
t.GetMethod("HasPermission", BindingFlags.Public Or BindingFlags.Instance)
_permissionDel = [Delegate].CreateDelegate(GetType(HasPermissionDelegate), _permissionObj, mi)
End If
End If
End If
Return _permissionDel
End Get
End Property
Private _permissionObj As Object = Nothing
Private _permissionDel As HasPermissionDelegate = Nothing
Public Function HasPermission(ByVal permission As String) As Boolean
If PermissionDelegate Is Nothing Then
Throw New NullReferenceException("The specified permission class (" + PermissionClass + ") could not be loaded/found.")
End If
Return PermissionDelegate(permission)
End Function
End Class
Public Class PermissionExtender
Inherits System.Web.UI.Control
Public Property ControlToSet As String
Get
Return If(ViewState("ControlToSet") Is Nothing, "", ViewState("ControlToSet").ToString())
End Get
Set(value As String)
ViewState("ControlToSet") = value
End Set
End Property
Public Property Permission As String
Get
Return If(ViewState("Permission") Is Nothing, "", ViewState("Permission").ToString())
End Get
Set(value As String)
ViewState("Permission") = value
End Set
End Property
Public Property MasterControllerID As String
Get
Return If(ViewState("MasterControllerID") Is Nothing, "", ViewState("MasterControllerID").ToString())
End Get
Set(value As String)
ViewState("MasterControllerID") = value
End Set
End Property
Protected ReadOnly Property MasterController As PermissionMasterControl
Get
If _mastercontroller Is Nothing Then
_mastercontroller = Me.Page.FindControl(MasterControllerID)
End If
Return _mastercontroller
End Get
End Property
Protected ReadOnly Property ManagedControl As Control
Get
If _controlToSet Is Nothing Then
_controlToSet = Me.NamingContainer.FindControl(ControlToSet)
End If
Return _controlToSet
End Get
End Property
Private _controlToSet As Control = Nothing
Private _mastercontroller As PermissionMasterControl = Nothing
Protected Overrides Sub OnLoad(e As System.EventArgs)
MyBase.OnLoad(e)
Dim bResult As Boolean = MasterController.HasPermission(Permission)
ManagedControl.Visible = bResult
End Sub
End Class
End Namespace

Resources