473,327 Members | 2,025 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

how to access user control in aspx file

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>
<SUBWAY:PEOPLEINFO id="Peopleinfo" runat="server" Caption="Employee
Information"></SUBWAY:PEOPLEINFO>
<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
Jan 12 '06 #1
5 2854
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>
<SUBWAY:PEOPLEINFO id="Peopleinfo" runat="server" Caption="Employee
Information"></SUBWAY:PEOPLEINFO>
<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

Jan 12 '06 #2
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>
<SUBWAY:PEOPLEINFO id="Peopleinfo" runat="server" Caption="Employee
Information"></SUBWAY:PEOPLEINFO>
<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

Jan 12 '06 #3
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>
<SUBWAY:PEOPLEINFO id="Peopleinfo" runat="server" Caption="Employee
Information"></SUBWAY:PEOPLEINFO>
<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

Jan 12 '06 #4
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>
> <SUBWAY:PEOPLEINFO id="Peopleinfo" runat="server" Caption="Employee
> Information"></SUBWAY:PEOPLEINFO>
> <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

Jan 12 '06 #5
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==?=" <be****@community.nospam>
| References: <7B**********************************@microsoft.co m>
<86**********************************@microsoft.co m>
<87**********************************@microsoft.co m>
| Subject: RE: how to access user control in aspx file
| Date: Wed, 11 Jan 2006 17:17:02 -0800
| Lines: 159
| Message-ID: <A9**********************************@microsoft.co m>
| 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>
| > > > <SUBWAY:PEOPLEINFO id="Peopleinfo" runat="server"
Caption="Employee
| > > > Information"></SUBWAY:PEOPLEINFO>
| > > > <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
|

Jan 12 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: mark | last post by:
I have an asp.net ecommerce web application on a remote web server. I'm using an Access database on the back end. I've notice a few strange things. When I mimic an multiple user environment by...
29
by: Patrick | last post by:
I have the following code, which regardless which works fine and logs to the EventViewer regardless of whether <processModel/> section of machine.config is set to username="SYSTEM" or "machine" ...
6
by: William Parker | last post by:
I have a web control I made called header.ascx. It has its own properties and methods I defined. But I cannot figure out how to access this control from my code behind page. I can create the...
5
by: djscratchnsniffing | last post by:
i know you can access an ascx's properties/methods from an aspx file. Let's say you have an aspx file with two code-behind files(ascx files). Can you access one of the ascx file's...
9
by: Nathan Sokalski | last post by:
I am trying to connect to a Microsoft Access Database from my ASP.NET Application. I use the following code to create my connection string: cmdSelect.Connection = New...
2
by: N. Demos | last post by:
I have a user control with code behind of which two instances are created/declared in my aspx page. The aspx page has code behind also, as I need to access methods of the usercontrols on page...
2
by: Joey | last post by:
I have a web app that uses forms authentication. The app also has a downloads section, and I need to be able to use <location> tags to control access to the downloadable files there (preferably by...
5
by: Mitchell S. Honnert | last post by:
Is there a way, given the full path of a folder on a network, that one can programatically tell if you have Read access to that folder? I have an application where the user is able to select a...
1
by: cpajoe2001 | last post by:
I am having an issue and after searching around online for a day and half now and finding others with the same problem but yet no solution to my issue I am looking for help. What i have is ServerA...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.