Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > how to access user control in aspx file

Reply
Thread Tools

how to access user control in aspx file

 
 
=?Utf-8?B?YzY3NjIyOA==?=
Guest
Posts: n/a
 
      01-12-2006
Hi,
I guess I am confused. In aspx script, I mean (you won't use
Codebehind="enrollinfo.aspx.vb", but mix code with html and code together)
You can access user control's property directly. Since I am useing visual
studio .net,
the html and code are seperated.
I have the following aspx code which has two user controls:
<%@ Register TagPrefix="Subway" TagName="Peopleinfo" Src="Peopleinfo.ascx" %>
<%@ Register TagPrefix="Subway" TagName="Address" Src="Address.ascx" %>
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="enrollinfo.aspx.vb" Inherits="subway.enrollinfo"%>
....
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<SUBWAY:ADDRESS id="address" runat="server" Caption="Home
Address"></SUBWAY:ADDRESS>
<p></p>
<SUBWAYEOPLEINFO id="Peopleinfo" runat="server" Caption="Employee
Information"></SUBWAYEOPLEINFO>
<p></p>
<asp:hyperlink id="Dependentlink" runat="server"
NavigateUrl="Peopleinfo1.aspx?SSN=" text="Add Dependents for
"></asp:hyperlink>
<asp:Button id="Button1" runat="server" Text="Add Dependents"></asp:Button>
</form>
</body>
</HTML>
and in enrollinfo.aspx.vb
I didn't see user controls' declaration in enrollinfo.aspx.vb, only two
server controls appear:
Protected WithEvents Dependentlink As System.Web.UI.WebControls.HyperLink
Protected WithEvents Button1 As System.Web.UI.WebControls.Button

so I added "Public People As PeopleInfo" myself, and later on,
and I have the following:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
People = New PeopleInfo
If People.SSN <> "" Then
Response.Redirect("Peopleinfo1.aspx?SSN" + People.SSN.ToString)
End If
End Sub

Peopleinfo is user control class and I tried to access its SSN property ,
but it gives
me error message something like: Null reference object accessed.
It seems that People.SSN is a wrong way, can you give me a hint? I have
properties for peopleinfo control already, here it is:

Public Class PeopleInfo
Inherits System.Web.UI.UserControl

Protected WithEvents txtFirstName As System.Web.UI.WebControls.TextBox
Protected WithEvents txtLastName As System.Web.UI.WebControls.TextBox
Protected WithEvents TxtSSN As System.Web.UI.WebControls.TextBox
Protected WithEvents TxtPlan As System.Web.UI.WebControls.TextBox
Protected WithEvents HyperLink1 As System.Web.UI.WebControls.HyperLink
Protected WithEvents Button1 As System.Web.UI.WebControls.Button

Private designerPlaceholderDeclaration As System.Object

Public Caption As String = "Dependent Information"
Private _ShowCaption As Boolean = True

Public Property ShowCaption() As Boolean
Get
Return _ShowCaption
End Get
Set(ByVal Value As Boolean)
_ShowCaption = value
End Set
End Property

Public Property FirstName() As String
Get
Return txtFirstName.Text
End Get
Set(ByVal Value As String)
txtFirstName.Text = Value
End Set
End Property

Public Property LastName() As String
Get
Return txtLastName.Text
End Get
Set(ByVal Value As String)
txtLastName.Text = Value
End Set
End Property

Public Property SSN() As String
Get
Return TxtSSN.Text
End Get
Set(ByVal Value As String)
TxtSSN.Text = Value
End Set
End Property

Public Property Plan() As String
Get
Return TxtPlan.Text
End Get
Set(ByVal Value As String)
TxtPlan.Text = Value
End Set
End Property


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

End Class
Betty
 
Reply With Quote
 
 
 
 
=?Utf-8?B?YzY3NjIyOA==?=
Guest
Posts: n/a
 
      01-12-2006
Hi,
I got it.
I just declare Protected WithEvents Peopleinfo1 As PeopleInfo (which I
thought the .net development tool will do it for me just like it did for
regular server controls.)
Then I access it in
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

If Peopleinfo1.SSN <> "" And Peopleinfo1.LastName <> "" Then
Response.Redirect("Peopleinfo1.aspx?SSN=" +
Peopleinfo1.SSN.ToString + "LastName=" + Peopleinfo1.LastName.ToString)
End If
End Sub

It worked out fine. But I didn't figure it out yet what the exact difference
from what I
did before.
--
Betty


"c676228" wrote:

> Hi,
> I guess I am confused. In aspx script, I mean (you won't use
> Codebehind="enrollinfo.aspx.vb", but mix code with html and code together)
> You can access user control's property directly. Since I am useing visual
> studio .net,
> the html and code are seperated.
> I have the following aspx code which has two user controls:
> <%@ Register TagPrefix="Subway" TagName="Peopleinfo" Src="Peopleinfo.ascx" %>
> <%@ Register TagPrefix="Subway" TagName="Address" Src="Address.ascx" %>
> <%@ Page Language="vb" AutoEventWireup="false"
> Codebehind="enrollinfo.aspx.vb" Inherits="subway.enrollinfo"%>
> ...
> <body MS_POSITIONING="GridLayout">
> <form id="Form1" method="post" runat="server">
> <SUBWAY:ADDRESS id="address" runat="server" Caption="Home
> Address"></SUBWAY:ADDRESS>
> <p></p>
> <SUBWAYEOPLEINFO id="Peopleinfo" runat="server" Caption="Employee
> Information"></SUBWAYEOPLEINFO>
> <p></p>
> <asp:hyperlink id="Dependentlink" runat="server"
> NavigateUrl="Peopleinfo1.aspx?SSN=" text="Add Dependents for
> "></asp:hyperlink>
> <asp:Button id="Button1" runat="server" Text="Add Dependents"></asp:Button>
> </form>
> </body>
> </HTML>
> and in enrollinfo.aspx.vb
> I didn't see user controls' declaration in enrollinfo.aspx.vb, only two
> server controls appear:
> Protected WithEvents Dependentlink As System.Web.UI.WebControls.HyperLink
> Protected WithEvents Button1 As System.Web.UI.WebControls.Button
>
> so I added "Public People As PeopleInfo" myself, and later on,
> and I have the following:
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> People = New PeopleInfo
> If People.SSN <> "" Then
> Response.Redirect("Peopleinfo1.aspx?SSN" + People.SSN.ToString)
> End If
> End Sub
>
> Peopleinfo is user control class and I tried to access its SSN property ,
> but it gives
> me error message something like: Null reference object accessed.
> It seems that People.SSN is a wrong way, can you give me a hint? I have
> properties for peopleinfo control already, here it is:
>
> Public Class PeopleInfo
> Inherits System.Web.UI.UserControl
>
> Protected WithEvents txtFirstName As System.Web.UI.WebControls.TextBox
> Protected WithEvents txtLastName As System.Web.UI.WebControls.TextBox
> Protected WithEvents TxtSSN As System.Web.UI.WebControls.TextBox
> Protected WithEvents TxtPlan As System.Web.UI.WebControls.TextBox
> Protected WithEvents HyperLink1 As System.Web.UI.WebControls.HyperLink
> Protected WithEvents Button1 As System.Web.UI.WebControls.Button
>
> Private designerPlaceholderDeclaration As System.Object
>
> Public Caption As String = "Dependent Information"
> Private _ShowCaption As Boolean = True
>
> Public Property ShowCaption() As Boolean
> Get
> Return _ShowCaption
> End Get
> Set(ByVal Value As Boolean)
> _ShowCaption = value
> End Set
> End Property
>
> Public Property FirstName() As String
> Get
> Return txtFirstName.Text
> End Get
> Set(ByVal Value As String)
> txtFirstName.Text = Value
> End Set
> End Property
>
> Public Property LastName() As String
> Get
> Return txtLastName.Text
> End Get
> Set(ByVal Value As String)
> txtLastName.Text = Value
> End Set
> End Property
>
> Public Property SSN() As String
> Get
> Return TxtSSN.Text
> End Get
> Set(ByVal Value As String)
> TxtSSN.Text = Value
> End Set
> End Property
>
> Public Property Plan() As String
> Get
> Return TxtPlan.Text
> End Get
> Set(ByVal Value As String)
> TxtPlan.Text = Value
> End Set
> End Property
>
>
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> 'Put user code to initialize the page here
> End Sub
>
> End Class
> Betty

 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
Guest
Posts: n/a
 
      01-12-2006
Just be careful not to design a real-life application that passes the SSN as
a QueryString parameter. This piece of information is confidential.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"c676228" wrote:

> Hi,
> I got it.
> I just declare Protected WithEvents Peopleinfo1 As PeopleInfo (which I
> thought the .net development tool will do it for me just like it did for
> regular server controls.)
> Then I access it in
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
>
> If Peopleinfo1.SSN <> "" And Peopleinfo1.LastName <> "" Then
> Response.Redirect("Peopleinfo1.aspx?SSN=" +
> Peopleinfo1.SSN.ToString + "LastName=" + Peopleinfo1.LastName.ToString)
> End If
> End Sub
>
> It worked out fine. But I didn't figure it out yet what the exact difference
> from what I
> did before.
> --
> Betty
>
>
> "c676228" wrote:
>
> > Hi,
> > I guess I am confused. In aspx script, I mean (you won't use
> > Codebehind="enrollinfo.aspx.vb", but mix code with html and code together)
> > You can access user control's property directly. Since I am useing visual
> > studio .net,
> > the html and code are seperated.
> > I have the following aspx code which has two user controls:
> > <%@ Register TagPrefix="Subway" TagName="Peopleinfo" Src="Peopleinfo.ascx" %>
> > <%@ Register TagPrefix="Subway" TagName="Address" Src="Address.ascx" %>
> > <%@ Page Language="vb" AutoEventWireup="false"
> > Codebehind="enrollinfo.aspx.vb" Inherits="subway.enrollinfo"%>
> > ...
> > <body MS_POSITIONING="GridLayout">
> > <form id="Form1" method="post" runat="server">
> > <SUBWAY:ADDRESS id="address" runat="server" Caption="Home
> > Address"></SUBWAY:ADDRESS>
> > <p></p>
> > <SUBWAYEOPLEINFO id="Peopleinfo" runat="server" Caption="Employee
> > Information"></SUBWAYEOPLEINFO>
> > <p></p>
> > <asp:hyperlink id="Dependentlink" runat="server"
> > NavigateUrl="Peopleinfo1.aspx?SSN=" text="Add Dependents for
> > "></asp:hyperlink>
> > <asp:Button id="Button1" runat="server" Text="Add Dependents"></asp:Button>
> > </form>
> > </body>
> > </HTML>
> > and in enrollinfo.aspx.vb
> > I didn't see user controls' declaration in enrollinfo.aspx.vb, only two
> > server controls appear:
> > Protected WithEvents Dependentlink As System.Web.UI.WebControls.HyperLink
> > Protected WithEvents Button1 As System.Web.UI.WebControls.Button
> >
> > so I added "Public People As PeopleInfo" myself, and later on,
> > and I have the following:
> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles Button1.Click
> > People = New PeopleInfo
> > If People.SSN <> "" Then
> > Response.Redirect("Peopleinfo1.aspx?SSN" + People.SSN.ToString)
> > End If
> > End Sub
> >
> > Peopleinfo is user control class and I tried to access its SSN property ,
> > but it gives
> > me error message something like: Null reference object accessed.
> > It seems that People.SSN is a wrong way, can you give me a hint? I have
> > properties for peopleinfo control already, here it is:
> >
> > Public Class PeopleInfo
> > Inherits System.Web.UI.UserControl
> >
> > Protected WithEvents txtFirstName As System.Web.UI.WebControls.TextBox
> > Protected WithEvents txtLastName As System.Web.UI.WebControls.TextBox
> > Protected WithEvents TxtSSN As System.Web.UI.WebControls.TextBox
> > Protected WithEvents TxtPlan As System.Web.UI.WebControls.TextBox
> > Protected WithEvents HyperLink1 As System.Web.UI.WebControls.HyperLink
> > Protected WithEvents Button1 As System.Web.UI.WebControls.Button
> >
> > Private designerPlaceholderDeclaration As System.Object
> >
> > Public Caption As String = "Dependent Information"
> > Private _ShowCaption As Boolean = True
> >
> > Public Property ShowCaption() As Boolean
> > Get
> > Return _ShowCaption
> > End Get
> > Set(ByVal Value As Boolean)
> > _ShowCaption = value
> > End Set
> > End Property
> >
> > Public Property FirstName() As String
> > Get
> > Return txtFirstName.Text
> > End Get
> > Set(ByVal Value As String)
> > txtFirstName.Text = Value
> > End Set
> > End Property
> >
> > Public Property LastName() As String
> > Get
> > Return txtLastName.Text
> > End Get
> > Set(ByVal Value As String)
> > txtLastName.Text = Value
> > End Set
> > End Property
> >
> > Public Property SSN() As String
> > Get
> > Return TxtSSN.Text
> > End Get
> > Set(ByVal Value As String)
> > TxtSSN.Text = Value
> > End Set
> > End Property
> >
> > Public Property Plan() As String
> > Get
> > Return TxtPlan.Text
> > End Get
> > Set(ByVal Value As String)
> > TxtPlan.Text = Value
> > End Set
> > End Property
> >
> >
> > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles MyBase.Load
> > 'Put user code to initialize the page here
> > End Sub
> >
> > End Class
> > Betty

 
Reply With Quote
 
=?Utf-8?B?YzY3NjIyOA==?=
Guest
Posts: n/a
 
      01-12-2006
Can I use cookie, what do you think is the best way?
--
Betty


"Phillip Williams" wrote:

> Just be careful not to design a real-life application that passes the SSN as
> a QueryString parameter. This piece of information is confidential.
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "c676228" wrote:
>
> > Hi,
> > I got it.
> > I just declare Protected WithEvents Peopleinfo1 As PeopleInfo (which I
> > thought the .net development tool will do it for me just like it did for
> > regular server controls.)
> > Then I access it in
> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles Button1.Click
> >
> > If Peopleinfo1.SSN <> "" And Peopleinfo1.LastName <> "" Then
> > Response.Redirect("Peopleinfo1.aspx?SSN=" +
> > Peopleinfo1.SSN.ToString + "LastName=" + Peopleinfo1.LastName.ToString)
> > End If
> > End Sub
> >
> > It worked out fine. But I didn't figure it out yet what the exact difference
> > from what I
> > did before.
> > --
> > Betty
> >
> >
> > "c676228" wrote:
> >
> > > Hi,
> > > I guess I am confused. In aspx script, I mean (you won't use
> > > Codebehind="enrollinfo.aspx.vb", but mix code with html and code together)
> > > You can access user control's property directly. Since I am useing visual
> > > studio .net,
> > > the html and code are seperated.
> > > I have the following aspx code which has two user controls:
> > > <%@ Register TagPrefix="Subway" TagName="Peopleinfo" Src="Peopleinfo.ascx" %>
> > > <%@ Register TagPrefix="Subway" TagName="Address" Src="Address.ascx" %>
> > > <%@ Page Language="vb" AutoEventWireup="false"
> > > Codebehind="enrollinfo.aspx.vb" Inherits="subway.enrollinfo"%>
> > > ...
> > > <body MS_POSITIONING="GridLayout">
> > > <form id="Form1" method="post" runat="server">
> > > <SUBWAY:ADDRESS id="address" runat="server" Caption="Home
> > > Address"></SUBWAY:ADDRESS>
> > > <p></p>
> > > <SUBWAYEOPLEINFO id="Peopleinfo" runat="server" Caption="Employee
> > > Information"></SUBWAYEOPLEINFO>
> > > <p></p>
> > > <asp:hyperlink id="Dependentlink" runat="server"
> > > NavigateUrl="Peopleinfo1.aspx?SSN=" text="Add Dependents for
> > > "></asp:hyperlink>
> > > <asp:Button id="Button1" runat="server" Text="Add Dependents"></asp:Button>
> > > </form>
> > > </body>
> > > </HTML>
> > > and in enrollinfo.aspx.vb
> > > I didn't see user controls' declaration in enrollinfo.aspx.vb, only two
> > > server controls appear:
> > > Protected WithEvents Dependentlink As System.Web.UI.WebControls.HyperLink
> > > Protected WithEvents Button1 As System.Web.UI.WebControls.Button
> > >
> > > so I added "Public People As PeopleInfo" myself, and later on,
> > > and I have the following:
> > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> > > System.EventArgs) Handles Button1.Click
> > > People = New PeopleInfo
> > > If People.SSN <> "" Then
> > > Response.Redirect("Peopleinfo1.aspx?SSN" + People.SSN.ToString)
> > > End If
> > > End Sub
> > >
> > > Peopleinfo is user control class and I tried to access its SSN property ,
> > > but it gives
> > > me error message something like: Null reference object accessed.
> > > It seems that People.SSN is a wrong way, can you give me a hint? I have
> > > properties for peopleinfo control already, here it is:
> > >
> > > Public Class PeopleInfo
> > > Inherits System.Web.UI.UserControl
> > >
> > > Protected WithEvents txtFirstName As System.Web.UI.WebControls.TextBox
> > > Protected WithEvents txtLastName As System.Web.UI.WebControls.TextBox
> > > Protected WithEvents TxtSSN As System.Web.UI.WebControls.TextBox
> > > Protected WithEvents TxtPlan As System.Web.UI.WebControls.TextBox
> > > Protected WithEvents HyperLink1 As System.Web.UI.WebControls.HyperLink
> > > Protected WithEvents Button1 As System.Web.UI.WebControls.Button
> > >
> > > Private designerPlaceholderDeclaration As System.Object
> > >
> > > Public Caption As String = "Dependent Information"
> > > Private _ShowCaption As Boolean = True
> > >
> > > Public Property ShowCaption() As Boolean
> > > Get
> > > Return _ShowCaption
> > > End Get
> > > Set(ByVal Value As Boolean)
> > > _ShowCaption = value
> > > End Set
> > > End Property
> > >
> > > Public Property FirstName() As String
> > > Get
> > > Return txtFirstName.Text
> > > End Get
> > > Set(ByVal Value As String)
> > > txtFirstName.Text = Value
> > > End Set
> > > End Property
> > >
> > > Public Property LastName() As String
> > > Get
> > > Return txtLastName.Text
> > > End Get
> > > Set(ByVal Value As String)
> > > txtLastName.Text = Value
> > > End Set
> > > End Property
> > >
> > > Public Property SSN() As String
> > > Get
> > > Return TxtSSN.Text
> > > End Get
> > > Set(ByVal Value As String)
> > > TxtSSN.Text = Value
> > > End Set
> > > End Property
> > >
> > > Public Property Plan() As String
> > > Get
> > > Return TxtPlan.Text
> > > End Get
> > > Set(ByVal Value As String)
> > > TxtPlan.Text = Value
> > > End Set
> > > End Property
> > >
> > >
> > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> > > System.EventArgs) Handles MyBase.Load
> > > 'Put user code to initialize the page here
> > > End Sub
> > >
> > > End Class
> > > Betty

 
Reply With Quote
 
=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
Guest
Posts: n/a
 
      01-12-2006
Consider storing it in the Session object
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"c676228" wrote:

> Can I use cookie, what do you think is the best way?
> --
> Betty
>
>
> "Phillip Williams" wrote:
>
> > Just be careful not to design a real-life application that passes the SSN as
> > a QueryString parameter. This piece of information is confidential.
> > --
> > HTH,
> > Phillip Williams
> > http://www.societopia.net
> > http://www.webswapp.com
> >
> >
> > "c676228" wrote:
> >
> > > Hi,
> > > I got it.
> > > I just declare Protected WithEvents Peopleinfo1 As PeopleInfo (which I
> > > thought the .net development tool will do it for me just like it did for
> > > regular server controls.)
> > > Then I access it in
> > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> > > System.EventArgs) Handles Button1.Click
> > >
> > > If Peopleinfo1.SSN <> "" And Peopleinfo1.LastName <> "" Then
> > > Response.Redirect("Peopleinfo1.aspx?SSN=" +
> > > Peopleinfo1.SSN.ToString + "LastName=" + Peopleinfo1.LastName.ToString)
> > > End If
> > > End Sub
> > >
> > > It worked out fine. But I didn't figure it out yet what the exact difference
> > > from what I
> > > did before.
> > > --
> > > Betty
> > >
> > >
> > > "c676228" wrote:
> > >
> > > > Hi,
> > > > I guess I am confused. In aspx script, I mean (you won't use
> > > > Codebehind="enrollinfo.aspx.vb", but mix code with html and code together)
> > > > You can access user control's property directly. Since I am useing visual
> > > > studio .net,
> > > > the html and code are seperated.
> > > > I have the following aspx code which has two user controls:
> > > > <%@ Register TagPrefix="Subway" TagName="Peopleinfo" Src="Peopleinfo.ascx" %>
> > > > <%@ Register TagPrefix="Subway" TagName="Address" Src="Address.ascx" %>
> > > > <%@ Page Language="vb" AutoEventWireup="false"
> > > > Codebehind="enrollinfo.aspx.vb" Inherits="subway.enrollinfo"%>
> > > > ...
> > > > <body MS_POSITIONING="GridLayout">
> > > > <form id="Form1" method="post" runat="server">
> > > > <SUBWAY:ADDRESS id="address" runat="server" Caption="Home
> > > > Address"></SUBWAY:ADDRESS>
> > > > <p></p>
> > > > <SUBWAYEOPLEINFO id="Peopleinfo" runat="server" Caption="Employee
> > > > Information"></SUBWAYEOPLEINFO>
> > > > <p></p>
> > > > <asp:hyperlink id="Dependentlink" runat="server"
> > > > NavigateUrl="Peopleinfo1.aspx?SSN=" text="Add Dependents for
> > > > "></asp:hyperlink>
> > > > <asp:Button id="Button1" runat="server" Text="Add Dependents"></asp:Button>
> > > > </form>
> > > > </body>
> > > > </HTML>
> > > > and in enrollinfo.aspx.vb
> > > > I didn't see user controls' declaration in enrollinfo.aspx.vb, only two
> > > > server controls appear:
> > > > Protected WithEvents Dependentlink As System.Web.UI.WebControls.HyperLink
> > > > Protected WithEvents Button1 As System.Web.UI.WebControls.Button
> > > >
> > > > so I added "Public People As PeopleInfo" myself, and later on,
> > > > and I have the following:
> > > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> > > > System.EventArgs) Handles Button1.Click
> > > > People = New PeopleInfo
> > > > If People.SSN <> "" Then
> > > > Response.Redirect("Peopleinfo1.aspx?SSN" + People.SSN.ToString)
> > > > End If
> > > > End Sub
> > > >
> > > > Peopleinfo is user control class and I tried to access its SSN property ,
> > > > but it gives
> > > > me error message something like: Null reference object accessed.
> > > > It seems that People.SSN is a wrong way, can you give me a hint? I have
> > > > properties for peopleinfo control already, here it is:
> > > >
> > > > Public Class PeopleInfo
> > > > Inherits System.Web.UI.UserControl
> > > >
> > > > Protected WithEvents txtFirstName As System.Web.UI.WebControls.TextBox
> > > > Protected WithEvents txtLastName As System.Web.UI.WebControls.TextBox
> > > > Protected WithEvents TxtSSN As System.Web.UI.WebControls.TextBox
> > > > Protected WithEvents TxtPlan As System.Web.UI.WebControls.TextBox
> > > > Protected WithEvents HyperLink1 As System.Web.UI.WebControls.HyperLink
> > > > Protected WithEvents Button1 As System.Web.UI.WebControls.Button
> > > >
> > > > Private designerPlaceholderDeclaration As System.Object
> > > >
> > > > Public Caption As String = "Dependent Information"
> > > > Private _ShowCaption As Boolean = True
> > > >
> > > > Public Property ShowCaption() As Boolean
> > > > Get
> > > > Return _ShowCaption
> > > > End Get
> > > > Set(ByVal Value As Boolean)
> > > > _ShowCaption = value
> > > > End Set
> > > > End Property
> > > >
> > > > Public Property FirstName() As String
> > > > Get
> > > > Return txtFirstName.Text
> > > > End Get
> > > > Set(ByVal Value As String)
> > > > txtFirstName.Text = Value
> > > > End Set
> > > > End Property
> > > >
> > > > Public Property LastName() As String
> > > > Get
> > > > Return txtLastName.Text
> > > > End Get
> > > > Set(ByVal Value As String)
> > > > txtLastName.Text = Value
> > > > End Set
> > > > End Property
> > > >
> > > > Public Property SSN() As String
> > > > Get
> > > > Return TxtSSN.Text
> > > > End Get
> > > > Set(ByVal Value As String)
> > > > TxtSSN.Text = Value
> > > > End Set
> > > > End Property
> > > >
> > > > Public Property Plan() As String
> > > > Get
> > > > Return TxtPlan.Text
> > > > End Get
> > > > Set(ByVal Value As String)
> > > > TxtPlan.Text = Value
> > > > End Set
> > > > End Property
> > > >
> > > >
> > > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> > > > System.EventArgs) Handles MyBase.Load
> > > > 'Put user code to initialize the page here
> > > > End Sub
> > > >
> > > > End Class
> > > > Betty

 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      01-12-2006
Hi betty,

yes, you can just explicitly declare the member control field in page
class(add withevents if using vb.net) so that the runtime will associate it
with the correct control instance... Also, in ASP.NET 2.0, we do not need
to do this since the new dynamic compilation model will automatically
generate the member field into page class.... In addition, we can also
programmatically find the control through Form1's Controls collection, we
can first get the Form1's reference and loop the sub controls to find all
the sub Usercontrols. e.g:

=====================
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Dim form1 As HtmlForm = Page.FindControl("form1")


Dim ctrl As Control

For Each ctrl In form1.Controls
Response.Write("<br>" & ctrl.GetType().ToString())
Next
End Sub
======================

Hope also helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Thread-Topic: how to access user control in aspx file
| thread-index: AcYXFeSnfIbuzmBbQECFQCOO+OLYnw==
| X-WBNR-Posting-Host: 12.25.78.238
| From: "=?Utf-8?B?YzY3NjIyOA==?=" <(E-Mail Removed)>
| References: <(E-Mail Removed)>
<(E-Mail Removed)>
<(E-Mail Removed)>
| Subject: RE: how to access user control in aspx file
| Date: Wed, 11 Jan 2006 17:17:02 -0800
| Lines: 159
| Message-ID: <(E-Mail Removed)>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:370228
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Can I use cookie, what do you think is the best way?
| --
| Betty
|
|
| "Phillip Williams" wrote:
|
| > Just be careful not to design a real-life application that passes the
SSN as
| > a QueryString parameter. This piece of information is confidential.
| > --
| > HTH,
| > Phillip Williams
| > http://www.societopia.net
| > http://www.webswapp.com
| >
| >
| > "c676228" wrote:
| >
| > > Hi,
| > > I got it.
| > > I just declare Protected WithEvents Peopleinfo1 As PeopleInfo (which
I
| > > thought the .net development tool will do it for me just like it did
for
| > > regular server controls.)
| > > Then I access it in
| > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
| > > System.EventArgs) Handles Button1.Click
| > >
| > > If Peopleinfo1.SSN <> "" And Peopleinfo1.LastName <> "" Then
| > > Response.Redirect("Peopleinfo1.aspx?SSN=" +
| > > Peopleinfo1.SSN.ToString + "LastName=" +
Peopleinfo1.LastName.ToString)
| > > End If
| > > End Sub
| > >
| > > It worked out fine. But I didn't figure it out yet what the exact
difference
| > > from what I
| > > did before.
| > > --
| > > Betty
| > >
| > >
| > > "c676228" wrote:
| > >
| > > > Hi,
| > > > I guess I am confused. In aspx script, I mean (you won't use
| > > > Codebehind="enrollinfo.aspx.vb", but mix code with html and code
together)
| > > > You can access user control's property directly. Since I am useing
visual
| > > > studio .net,
| > > > the html and code are seperated.
| > > > I have the following aspx code which has two user controls:
| > > > <%@ Register TagPrefix="Subway" TagName="Peopleinfo"
Src="Peopleinfo.ascx" %>
| > > > <%@ Register TagPrefix="Subway" TagName="Address"
Src="Address.ascx" %>
| > > > <%@ Page Language="vb" AutoEventWireup="false"
| > > > Codebehind="enrollinfo.aspx.vb" Inherits="subway.enrollinfo"%>
| > > > ...
| > > > <body MS_POSITIONING="GridLayout">
| > > > <form id="Form1" method="post" runat="server">
| > > > <SUBWAY:ADDRESS id="address" runat="server" Caption="Home
| > > > Address"></SUBWAY:ADDRESS>
| > > > <p></p>
| > > > <SUBWAYEOPLEINFO id="Peopleinfo" runat="server"
Caption="Employee
| > > > Information"></SUBWAYEOPLEINFO>
| > > > <p></p>
| > > > <asp:hyperlink id="Dependentlink" runat="server"
| > > > NavigateUrl="Peopleinfo1.aspx?SSN=" text="Add Dependents for
| > > > "></asp:hyperlink>
| > > > <asp:Button id="Button1" runat="server" Text="Add
Dependents"></asp:Button>
| > > > </form>
| > > > </body>
| > > > </HTML>
| > > > and in enrollinfo.aspx.vb
| > > > I didn't see user controls' declaration in enrollinfo.aspx.vb, only
two
| > > > server controls appear:
| > > > Protected WithEvents Dependentlink As
System.Web.UI.WebControls.HyperLink
| > > > Protected WithEvents Button1 As System.Web.UI.WebControls.Button
| > > >
| > > > so I added "Public People As PeopleInfo" myself, and later on,
| > > > and I have the following:
| > > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
| > > > System.EventArgs) Handles Button1.Click
| > > > People = New PeopleInfo
| > > > If People.SSN <> "" Then
| > > > Response.Redirect("Peopleinfo1.aspx?SSN" +
People.SSN.ToString)
| > > > End If
| > > > End Sub
| > > >
| > > > Peopleinfo is user control class and I tried to access its SSN
property ,
| > > > but it gives
| > > > me error message something like: Null reference object accessed.
| > > > It seems that People.SSN is a wrong way, can you give me a hint? I
have
| > > > properties for peopleinfo control already, here it is:
| > > >
| > > > Public Class PeopleInfo
| > > > Inherits System.Web.UI.UserControl
| > > >
| > > > Protected WithEvents txtFirstName As
System.Web.UI.WebControls.TextBox
| > > > Protected WithEvents txtLastName As
System.Web.UI.WebControls.TextBox
| > > > Protected WithEvents TxtSSN As System.Web.UI.WebControls.TextBox
| > > > Protected WithEvents TxtPlan As
System.Web.UI.WebControls.TextBox
| > > > Protected WithEvents HyperLink1 As
System.Web.UI.WebControls.HyperLink
| > > > Protected WithEvents Button1 As System.Web.UI.WebControls.Button
| > > >
| > > > Private designerPlaceholderDeclaration As System.Object
| > > >
| > > > Public Caption As String = "Dependent Information"
| > > > Private _ShowCaption As Boolean = True
| > > >
| > > > Public Property ShowCaption() As Boolean
| > > > Get
| > > > Return _ShowCaption
| > > > End Get
| > > > Set(ByVal Value As Boolean)
| > > > _ShowCaption = value
| > > > End Set
| > > > End Property
| > > >
| > > > Public Property FirstName() As String
| > > > Get
| > > > Return txtFirstName.Text
| > > > End Get
| > > > Set(ByVal Value As String)
| > > > txtFirstName.Text = Value
| > > > End Set
| > > > End Property
| > > >
| > > > Public Property LastName() As String
| > > > Get
| > > > Return txtLastName.Text
| > > > End Get
| > > > Set(ByVal Value As String)
| > > > txtLastName.Text = Value
| > > > End Set
| > > > End Property
| > > >
| > > > Public Property SSN() As String
| > > > Get
| > > > Return TxtSSN.Text
| > > > End Get
| > > > Set(ByVal Value As String)
| > > > TxtSSN.Text = Value
| > > > End Set
| > > > End Property
| > > >
| > > > Public Property Plan() As String
| > > > Get
| > > > Return TxtPlan.Text
| > > > End Get
| > > > Set(ByVal Value As String)
| > > > TxtPlan.Text = Value
| > > > End Set
| > > > End Property
| > > >
| > > >
| > > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
| > > > System.EventArgs) Handles MyBase.Load
| > > > 'Put user code to initialize the page here
| > > > End Sub
| > > >
| > > > End Class
| > > > Betty
|

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
User Control to Control Other User Control Jonathan Wood ASP .Net 4 02-02-2010 03:41 PM
Access user control from other user control Chris Zopers ASP .Net 3 04-27-2009 10:32 PM
persisting changes to a control outside a user control from the user control? Mad Scientist Jr ASP .Net 0 03-22-2006 08:02 AM
Access inherited aspx control from base aspx ? Jeff User ASP .Net 3 12-02-2005 04:58 AM
adding main.aspx.vb & main.aspx.resx under aspx John M ASP .Net 1 05-29-2005 09:27 PM



Advertisments