F
fernandezr
Hi, I've got a user control that is referenced twice on the same page
and I'd like to access the textbox values on postback so I can update a
database. How can get the values for each instance of the user control
text box?
Here is the user control ascx file:
<%@ Control Language="C#" EnableViewState="true"
AutoEventWireup="true" CodeFile="ucAddress.ascx.cs"
Inherits="ucAddress" %>
<asp:Table ID="tblAddress" runat="server" BorderWidth="0"
CellPadding="0" CellSpacing="0">
<asp:TableRow>
<asp:TableCell>
<asp:Table ID="tblAddr1" runat="server" BorderWidth="0"
CellPadding="0" CellSpacing="0">
<asp:TableRow>
<asp:TableCell>
<asp:Label ID="lblAddrLine1" runat="server" Text="Line1"
Width="60px"></asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtAddrLine1" runat="server"
Width="390px" /><br />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
Here is the code behind ascx.cs file:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class ucAddress : System.Web.UI.UserControl
{
public void textboxSet(string controlName, string txtAddr, int
txtAddrMaxLength, int txtAddrWidth, bool blnAddrReadOnly)
{
TextBox objTxtbox;
objTxtbox = (TextBox)this.FindControl(controlName);
objTxtbox.Text = txtAddr;
objTxtbox.MaxLength = txtAddrMaxLength;
objTxtbox.Width = txtAddrWidth;
if (blnAddrReadOnly == true)
{
objTxtbox.ReadOnly = true;
objTxtbox.BorderWidth = 0;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
Here is the aspx page:
<%@ Page trace="false" EnableViewState="true"
MasterPageFile="~/MOR.master" Title="MOR Profile" Language="C#"
AutoEventWireup="true" CodeFile="profile.aspx.cs" Inherits="profile" %>
<%@ Register TagPrefix="Address" TagName="HomeAddr"
Src="~/controls/ucAddress.ascx" %>
<%@ Register TagPrefix="Address" TagName="BusnAddr"
Src="~/controls/ucAddress.ascx" %>
<asp:content ID="Content3" ContentPlaceHolderID="Main" runat="server">
<Address:HomeAddr ID="HomeAddr" runat="server" />
<Address:BusnAddr ID="BusnAddr" runat="server" />
<asp:Button ID="btnUpdate" Text="Update Profile" runat="server" />
<br />
</asp:content>
Here is the aspx.cs file:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Collections.Generic;
using MORSite.properties;
public partial class profile : System.Web.UI.Page
{
protected void Page_PreInit(object sender, EventArgs e)
{
}
protected void Page_Load(object sender, EventArgs e)
{
UserProfile U = new UserProfile();
U = SQLRoutines.GetProfile(3275);
HomeAddr.textboxSet("txtAddrLine1", U.HomeAddrLine1, 40,
390, false);
BusnAddr.textboxSet("txtAddrLine1", U.BusnAddrLine1, 40,
390, false);
}
}
Thanks,
Robert
and I'd like to access the textbox values on postback so I can update a
database. How can get the values for each instance of the user control
text box?
Here is the user control ascx file:
<%@ Control Language="C#" EnableViewState="true"
AutoEventWireup="true" CodeFile="ucAddress.ascx.cs"
Inherits="ucAddress" %>
<asp:Table ID="tblAddress" runat="server" BorderWidth="0"
CellPadding="0" CellSpacing="0">
<asp:TableRow>
<asp:TableCell>
<asp:Table ID="tblAddr1" runat="server" BorderWidth="0"
CellPadding="0" CellSpacing="0">
<asp:TableRow>
<asp:TableCell>
<asp:Label ID="lblAddrLine1" runat="server" Text="Line1"
Width="60px"></asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtAddrLine1" runat="server"
Width="390px" /><br />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
Here is the code behind ascx.cs file:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class ucAddress : System.Web.UI.UserControl
{
public void textboxSet(string controlName, string txtAddr, int
txtAddrMaxLength, int txtAddrWidth, bool blnAddrReadOnly)
{
TextBox objTxtbox;
objTxtbox = (TextBox)this.FindControl(controlName);
objTxtbox.Text = txtAddr;
objTxtbox.MaxLength = txtAddrMaxLength;
objTxtbox.Width = txtAddrWidth;
if (blnAddrReadOnly == true)
{
objTxtbox.ReadOnly = true;
objTxtbox.BorderWidth = 0;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
Here is the aspx page:
<%@ Page trace="false" EnableViewState="true"
MasterPageFile="~/MOR.master" Title="MOR Profile" Language="C#"
AutoEventWireup="true" CodeFile="profile.aspx.cs" Inherits="profile" %>
<%@ Register TagPrefix="Address" TagName="HomeAddr"
Src="~/controls/ucAddress.ascx" %>
<%@ Register TagPrefix="Address" TagName="BusnAddr"
Src="~/controls/ucAddress.ascx" %>
<asp:content ID="Content3" ContentPlaceHolderID="Main" runat="server">
<Address:HomeAddr ID="HomeAddr" runat="server" />
<Address:BusnAddr ID="BusnAddr" runat="server" />
<asp:Button ID="btnUpdate" Text="Update Profile" runat="server" />
<br />
</asp:content>
Here is the aspx.cs file:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Collections.Generic;
using MORSite.properties;
public partial class profile : System.Web.UI.Page
{
protected void Page_PreInit(object sender, EventArgs e)
{
}
protected void Page_Load(object sender, EventArgs e)
{
UserProfile U = new UserProfile();
U = SQLRoutines.GetProfile(3275);
HomeAddr.textboxSet("txtAddrLine1", U.HomeAddrLine1, 40,
390, false);
BusnAddr.textboxSet("txtAddrLine1", U.BusnAddrLine1, 40,
390, false);
}
}
Thanks,
Robert