R
rn5a
Assume that a ASPX page uses a user control named Address.ascx which
has 2 TextBoxes. This ASCX page creates 2 properties named 'Address' &
'City' using the Get & Set statements:
<script runat="server">
Public Property Address() As String
Get
Address = txtAddress.Text
End Get
Set(ByVal value As String)
txtAddress.Text = value
End Set
End Property
Public Property City() As String
Get
City = txtCity.Text
End Get
Set(ByVal value As String)
txtCity.Text = value
End Set
End Property
</script>
Address: <asp:TextBox ID="txtAddress" runat="server"/>
City: <asp:TextBox ID="txtCity" runat="server"/>
This function in a VB class file takes UserID as a parameter & returns
a SqlDataReader to the calling function which exists in a ASPX page:
Namespace NConnect
Public Class Cart
Private sqlConn As New SqlConnection(".....")
Public Function GetAddress(ByVal UserID As Integer) As
SqlDataReader
Dim sqlCmd As SqlCommand
Dim sqlReader As SqlDataReader
sqlCmd = New SqlCommand("NETGetAddress", sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
Try
With sqlCmd
.Parameters.Add("@UserID", SqlDbType.Int).Value =
UserID
End With
sqlConn.Open()
sqlReader = sqlCmd.ExecuteReader
Catch ex As Exception
Throw ex
End Try
Return sqlReader
End Function
End Class
End Namespace
Using vbc, I successfully compiled the above class file into a DLL
named NConnect.dll.
This is the ASPX page that uses the user control & the DLL:
<%@ Register TagPrefix="NETConnect" TagName="Address"
Src="Address.ascx" %>
<%@ Import Namespace="NConnect" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">
Public billAddress As address_ascx
Public shipAddress As address_ascx
Sub Page_Load(......)
Dim sqlReader As SqlDataReader
Dim iUserID As Integer
Dim boCart As Cart
boCart = New Cart
billAddress = Page.LoadControl("Address.ascx")
billAddress.ID = "ncBilling"
shipAddress = Page.LoadControl("Address.ascx")
shipAddress.ID = "ncShipping"
'retrieving UserID by calling a function
sqlReader = boCart.GetAddress(iUserID)
While(sqlReader.Read)
billAddress.Address = sqlReader.GetString(1)
billAddress.City = sqlReader.GetString(2)
shipAddress.Address = sqlReader.GetString(1)
shipAddress.City = sqlReader.GetString(2)
End While
pnlBillAddress.Controls.Add(billAddress)
pnlShipAddress.Controls.Add(shipAddress)
End Sub
Sub Submit_Click(obj As Object, ea As EventArgs)
.............
'how do I retrieve the data a user
'has entered in the 4 TextBoxes?
End Sub
</script>
<form runat="server">
<aspanel ID="pnlBillAddress" runat="server"/><br>
<aspanel ID="pnlShipAddress" runat="server"/><br>
<asp:Button ID="btn" OnClick="Submit_Click" Text="Submit"
runat="server"/>
</form>
The ASPX page displays 2 Panels with each Panel displaying 2 TextBoxes.
Now since the 4 TextBoxes are being added to the ASPX page dynamically,
how do I find out what is the ID of each of the 4 TextBoxes so that
Submit_Click sub can retrieve the data that has been entered by a user
in the 4 TextBoxes?
has 2 TextBoxes. This ASCX page creates 2 properties named 'Address' &
'City' using the Get & Set statements:
<script runat="server">
Public Property Address() As String
Get
Address = txtAddress.Text
End Get
Set(ByVal value As String)
txtAddress.Text = value
End Set
End Property
Public Property City() As String
Get
City = txtCity.Text
End Get
Set(ByVal value As String)
txtCity.Text = value
End Set
End Property
</script>
Address: <asp:TextBox ID="txtAddress" runat="server"/>
City: <asp:TextBox ID="txtCity" runat="server"/>
This function in a VB class file takes UserID as a parameter & returns
a SqlDataReader to the calling function which exists in a ASPX page:
Namespace NConnect
Public Class Cart
Private sqlConn As New SqlConnection(".....")
Public Function GetAddress(ByVal UserID As Integer) As
SqlDataReader
Dim sqlCmd As SqlCommand
Dim sqlReader As SqlDataReader
sqlCmd = New SqlCommand("NETGetAddress", sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
Try
With sqlCmd
.Parameters.Add("@UserID", SqlDbType.Int).Value =
UserID
End With
sqlConn.Open()
sqlReader = sqlCmd.ExecuteReader
Catch ex As Exception
Throw ex
End Try
Return sqlReader
End Function
End Class
End Namespace
Using vbc, I successfully compiled the above class file into a DLL
named NConnect.dll.
This is the ASPX page that uses the user control & the DLL:
<%@ Register TagPrefix="NETConnect" TagName="Address"
Src="Address.ascx" %>
<%@ Import Namespace="NConnect" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">
Public billAddress As address_ascx
Public shipAddress As address_ascx
Sub Page_Load(......)
Dim sqlReader As SqlDataReader
Dim iUserID As Integer
Dim boCart As Cart
boCart = New Cart
billAddress = Page.LoadControl("Address.ascx")
billAddress.ID = "ncBilling"
shipAddress = Page.LoadControl("Address.ascx")
shipAddress.ID = "ncShipping"
'retrieving UserID by calling a function
sqlReader = boCart.GetAddress(iUserID)
While(sqlReader.Read)
billAddress.Address = sqlReader.GetString(1)
billAddress.City = sqlReader.GetString(2)
shipAddress.Address = sqlReader.GetString(1)
shipAddress.City = sqlReader.GetString(2)
End While
pnlBillAddress.Controls.Add(billAddress)
pnlShipAddress.Controls.Add(shipAddress)
End Sub
Sub Submit_Click(obj As Object, ea As EventArgs)
.............
'how do I retrieve the data a user
'has entered in the 4 TextBoxes?
End Sub
</script>
<form runat="server">
<aspanel ID="pnlBillAddress" runat="server"/><br>
<aspanel ID="pnlShipAddress" runat="server"/><br>
<asp:Button ID="btn" OnClick="Submit_Click" Text="Submit"
runat="server"/>
</form>
The ASPX page displays 2 Panels with each Panel displaying 2 TextBoxes.
Now since the 4 TextBoxes are being added to the ASPX page dynamically,
how do I find out what is the ID of each of the 4 TextBoxes so that
Submit_Click sub can retrieve the data that has been entered by a user
in the 4 TextBoxes?