i have public property in user control and i need access to this property from HTML for parent for this user control
Public Property ActorID As Integer
Set(value As Integer)
ViewState("ActorID") = value
End Set
Get
Return ViewState("ActorID")
End Get
End Property
<uc3:Hos_Applicants ID="Hos_Applicants1" runat="server" />
<uc3:Hos_Applicants ID="Hos_Applicants1" runat="server" ActorID="2" />
you can access to property and set value in user control from parent asp page
Related
After exposing a public property in Top.Master it can be accessed in any child page that has a master type reference on its page.
How can the same properties be accessed from a nested page?
I tried to cascade the properties down the heirarchy but the child page errors when trying to access it.
I would prefer to access the exposed top.master property directly from the nested content page but am unsure of a good way to do this.
TOP.MASTER
<asp:Label ID="lblMsg" ClientIDMode="Static" runat="Server" />
TOP.MASTER.VB
Partial Public Class TopMaster
Inherits MasterPage
Public Property Msg As String
Get
Return lblMsg.Text
End Get
Set(value As String)
lblMsg.Text = value
End Set
End Property
End Class
CHILD.MASTER
<%# MasterType VirtualPath="~/Top.Master" %>
CHILD.MASTER.VB
Master.Msg = "Success"
CHILD.PAGE
<%# MasterType VirtualPath="~/Child.Master" %>
CHILD.PAGE.VB
Master.Master.Msg = "Success"
In your child.master class you can create a Msg property that would proxy the top master Msg property
You can add the following code in child.master.vb
Public Property Msg As String
Get
Return Master.Msg
End Get
Set(value As String)
Master.Msg = value
End Set
End Property
then in your child.page.vb you can access this property doing
Master.Msg = "Success"
I have been trying to create a property in a custom web control (DropDownMenu) that references another control (Button) on the page.
This is my property declaration (inside DropDownMenu):
<Bindable(True), Category("Behaviour"), Localizable(True)>
Private _ToggleParent As Control
Public Property ToggleParent As Control
Get
Return _ToggleParent
End Get
Set(value As Control)
_ToggleParent = value
End Set
End Property
And this is my mark-up:
<boot:Button runat="server" ID="t1" Text="hi" />
<boot:DropDownMenu runat="server" ToggleParent="t1" >
<MenuItems>
<boot:MenuItem runat="server" Text="test"></boot:MenuItem>
<boot:MenuItem runat="server" Text="test"></boot:MenuItem>
</MenuItems>
</boot:DropDownMenu>
This is what I get as the error:
Cannot create an object of type 'System.Web.UI.Control' from its string representation 't1' for the 'ToggleParent' property.
Same error if I remove the quotes. I understand I could FindControl based on a string representation of the control ID, but I would prefer to pass the control directly through the property.
I have a aspx page that several of the same usercontrols on the page. The usercontrol houses a textbox that has a Required field validator on it. The validator works but the setonfocus="true" does not seem to be working, further more, the button the aspx page when the validator shows the error message, the button still fires the code behind.
Here is what the aspx page looks like as far as the user control and the the button.
ucTB:ucTextBox ID="ucTextR" runat="server" ValidationGroup="txtRequired" Required="_true"
asp:Button ID="btnSave" runat="server" Text="Click" ValidationGroup="txtRequired"
and the usercontrol validator
asp:RequiredFieldValidator ID="rfTextBox" runat="server" ControlToValidate="txtTextBox"
SetFocusOnError="true" ErrorMessage="Required Field" EnableClientScript="false"
the user control has been wired to grab the validator from the aspx page and use it in the usercontrol... something like this
Public Property ValidationGroup() As String
Get
Return CType(ViewState("ValidationGroup"), String)
End Get
Set(ByVal Value As String)
ViewState("ValidationGroup") = Value
End Set
End Property
Protected Sub AssignValidation()
For Each control As Control In Me.Controls
Dim [property] As PropertyInfo = control.[GetType]().GetProperty("ValidationGroup")
If [property] Is Nothing Then
Continue For
End If
[property].SetValue(control, ValidationGroup, Nothing)
Next
End Sub
and i load the AssignValidation on page_load
anyway.. hope this is the info you need to point me in the right direction.
What i'm looking to do is if the required field validator to put the focus on the usercontrol if there is nothing in the usercontrol text box and also for the button on the aspx page not to fire.. like i think it behaves if you use a validator on a aspx page with no usercontrol
thanks
shannon
You can't set the user control to visible because it's not a visible container. You can set the focus yourself programmatically. See this:
http://forums.digitalpoint.com/showthread.php?t=282224
Or, you can programmably set the validator to the ID of the textbox within the user control; expose a textboxID property in the user control code-behind which returns the textbox's ID, and have your page assign the validator's controltovalidateID to this.
I have a composite control that has a large number of properties that can be used to style the control. I want to group these properties yet still maintain some of the properties in the ViewState
The markup for the control would look like this:
e.g.
<cc:Test id="test">
<Toolbar Items="add,delete" Enabled="true" />
<Grid Enabled="true" AllowSort="true" AllowFilter="true" />
</cc:Test>
My code looks something like this
<ParseChildren(true)> <PersistChildren(true)> _
Public Class Test Inherits CompositeControl
Private _grid As New GridStyle();
<PersistenceMode(PersistenceMode.InnerProperty)> _
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public ReadOnly Property Grid As GridStyle
Get
Return _grid;
End Get
End Property
End Class
Public Class GridStyle
private _allowFilter As Boolean = False;
Public Property AllowFilter As Boolean
Get
Return _allowFilter
End Get
Set(value As Boolean)
_allowFilter = value
End Set
End Property
End Class
ViewState is not accessible from the GridStyle class so how would I maintain the state of the AllowFilter property in the ViewState?
In your custom control (or make wrappers for standard controls used within a custom control) you need to override SaveViewState and LoadViewState
This is well documented on MSDN and the web in general
I would like to have an aspx page that contains something like....
<form id="form1" runas=server >
Hello <%= Me.UserName() %>
</form>
and a code-behind something like...
Public Class Somepage
inherits SomeOtherPage
Private Readonly Property UserName() as String
Get
return "Rory"
End Get
End Property
End Class
I have tried this code but the aspx errors claiming that UserName is not declared.
What is the proper way to do this?
Mark the property as Protected, not Private.
Protected Readonly Property UserName() as String
Get
return "Rory"
End Get
End Property