M
miketayloruk
Hi,
I’m trying to assign a property (record _id) to a user control from
its parent page. I have set up a public property in my user control
and tried to assign a value to it from the parent.
I presumed that once the value had been passed to the user control I
could then display it via a button click as per my example, which
doesn’t appear to work, ie when the button is clicked it does show the
ID value it should have received.
I eventually want to nest usercomtrols a few layers deep and I’m
trying to understand how I can pass information up and down the
layers.
User control:
<%@ Control Language="VB" ClassName="test" %>
<script runat="server">
Private _myid As Integer
Public Property myid() As Integer
Set(ByVal value As Integer)
_myid = value
'display the value recieved
lblset.Text = "_myid being assigned value = " & _myid
End Set
Get
Return _myid
End Get
End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
lblload.Text = "Value at page load event = " & _myid
End Sub
Protected Sub lblafterclick_Click(ByVal sender As Object, ByVal e
As System.EventArgs) Handles btnSee.Click
lblreceived.Text = _myid
End Sub
</script>
<asp:Label ID="lblset" runat="server" Text="When the public property
is changed it will be displayed here" Width="100%"></asp:Label><br />
<br />
<asp:Label ID="lblload" runat="server" Text="The public property at
the page_load event will be displayed here" Width="100%"></
asp:Label><br />
<br />
<asp:Button ID="btnSee" runat="server" Text="Click to see ID Value
received" /><br />
<br />
<asp:Label ID="lblreceived" runat="server"></asp:Label>
Parent Page:
<%@ Page Language="VB" %>
<%@ Register Src="TCV3_controls/test.ascx" TagName="test"
TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Test1.myid = 42
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>test</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table cellpadding="2" cellspacing="2">
<tr>
<td>
<asp:Button ID="Button1" runat="server" Text="Send
ID Value (42)" OnClick="Button1_Click" /></td>
</tr>
<tr>
<td bgcolor="#ffffcc" >
<uc1:test ID="Test1" runat="server" />
</td>
</tr>
</table>
<br />
</div>
</form>
</body>
</html>
I’m trying to assign a property (record _id) to a user control from
its parent page. I have set up a public property in my user control
and tried to assign a value to it from the parent.
I presumed that once the value had been passed to the user control I
could then display it via a button click as per my example, which
doesn’t appear to work, ie when the button is clicked it does show the
ID value it should have received.
I eventually want to nest usercomtrols a few layers deep and I’m
trying to understand how I can pass information up and down the
layers.
User control:
<%@ Control Language="VB" ClassName="test" %>
<script runat="server">
Private _myid As Integer
Public Property myid() As Integer
Set(ByVal value As Integer)
_myid = value
'display the value recieved
lblset.Text = "_myid being assigned value = " & _myid
End Set
Get
Return _myid
End Get
End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
lblload.Text = "Value at page load event = " & _myid
End Sub
Protected Sub lblafterclick_Click(ByVal sender As Object, ByVal e
As System.EventArgs) Handles btnSee.Click
lblreceived.Text = _myid
End Sub
</script>
<asp:Label ID="lblset" runat="server" Text="When the public property
is changed it will be displayed here" Width="100%"></asp:Label><br />
<br />
<asp:Label ID="lblload" runat="server" Text="The public property at
the page_load event will be displayed here" Width="100%"></
asp:Label><br />
<br />
<asp:Button ID="btnSee" runat="server" Text="Click to see ID Value
received" /><br />
<br />
<asp:Label ID="lblreceived" runat="server"></asp:Label>
Parent Page:
<%@ Page Language="VB" %>
<%@ Register Src="TCV3_controls/test.ascx" TagName="test"
TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Test1.myid = 42
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>test</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table cellpadding="2" cellspacing="2">
<tr>
<td>
<asp:Button ID="Button1" runat="server" Text="Send
ID Value (42)" OnClick="Button1_Click" /></td>
</tr>
<tr>
<td bgcolor="#ffffcc" >
<uc1:test ID="Test1" runat="server" />
</td>
</tr>
</table>
<br />
</div>
</form>
</body>
</html>