Re: Accessing members of a user control from the aspx page.
From: Alvin Bruney [MVP] (vapor)
Date: 09/30/04
- Next message: Andrew: "Change user control output at runtime?"
- Previous message: Michael Persaud: "Ecards in ASP.NET"
- Next in thread: David A. Coursey: "Re: Accessing members of a user control from the aspx page."
- Reply: David A. Coursey: "Re: Accessing members of a user control from the aspx page."
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 30 Sep 2004 11:15:45 -0500
you've made the textbox a static instance. controls cannot be static because
it interfers with the viewstate mechanism. instead you should store the data
in a static variable. consider a get/set method to move the data in the
textbox into a static reference
-- Regards, Alvin Bruney [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx] Got tidbits? Get it here... http://tinyurl.com/27*** "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message news:u%232UTwnpEHA.592@TK2MSFTNGP11.phx.gbl... > do you have this compiling. i swear mine compiled a while ago. now it will > not compile at this line > control.txtFirstName.Text = "This won't work"; > > rightfully stating that txtFirstName.Text is inaccessible. > > > > check again to see if it compiles. if it does, zip the bare bones and send > it to me > > vapordan@hotmail.com > > i have a fix for it but it might be moot if it doesn't compile correctly > -- > Regards, > Alvin Bruney > [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx] > Got tidbits? Get it here... http://tinyurl.com/27*** > "David A. Coursey" <DavidACoursey@discussions.microsoft.com> wrote in > message news:5C524A55-2EB2-4DB4-B265-7AE1D81476CE@microsoft.com... >> Ok, here you go. >> >> aspx page: >> >> <%@ Register TagPrefix="s2f" TagName="control" src="control.ascx" %> >> <%@ Page language="c#" Codebehind="main.aspx.cs" AutoEventWireup="false" >> Inherits="TESTbug.main" %> >> <html> >> <head> >> <title>test</title> >> </head> >> <body> >> <form id=mainForm method=post runat="server"> >> <s2f:control id="control" runat="server"></s2f:control> >> </form> >> </body> >> </html> >> >> >> ascx page >> >> >> <%@ Control Language="c#" AutoEventWireup="false" >> Codebehind="control.ascx.cs" Inherits="TESTbug.Controls.control" >> TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %> >> <asp:textbox id="txtFirstName" runat="server"></asp:textbox> >> >> >> "Alvin Bruney [MVP]" wrote: >> >>> post the html please >>> >>> -- >>> Regards, >>> Alvin Bruney >>> [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx] >>> Got tidbits? Get it here... http://tinyurl.com/27*** >>> "Dave" <Dave@discussions.microsoft.com> wrote in message >>> news:65486A4E-B0A6-4A9E-AD4A-F2C1BB7D48DB@microsoft.com... >>> >> post a small sample which demonstrates the problem i will take a look >>> >> use this as a guide http://www.yoda.arachsys.com/csharp/complete.html >>> > >>> > >>> > Ok, I read your document and this is as short and sweet as I could get >>> > it. >>> > It requires an .aspx page and an .ascx web user control. I'm leaving >>> > off >>> > the >>> > html for the aspx and ascx pages because all you need to do is drop a >>> > textbox >>> > on the control and drop the control on the page. At this point I >>> > think I >>> > just have something fundamentally wrong, but I would like to find out >>> > why >>> > this isn't "allowed". >>> > >>> > >>> > .aspx code behind page >>> > >>> > >>> > using System; >>> > using TESTbug.Controls; >>> > >>> > namespace TESTbug >>> > { >>> > /// <summary> >>> > /// Summary description for cma. >>> > /// </summary> >>> > public class main : System.Web.UI.Page >>> > { >>> > protected Microsoft.Web.UI.WebControls.TabStrip tabStrip; >>> > protected Microsoft.Web.UI.WebControls.MultiPage multiPage; >>> > >>> > private void Page_Load(object sender, System.EventArgs e) >>> > { >>> > control.txtFirstName.Text = "This won't work"; >>> > } >>> > >>> > >>> > #region Web Form Designer generated code >>> > //left out for clarity, nothing has >>> > been >>> > altered >>> > #endregion >>> > >>> > } >>> > } >>> > >>> > >>> > >>> > >>> > ascx page code behind >>> > >>> > namespace TESTbug.Controls >>> > { >>> > using System; >>> > >>> > /// <summary> >>> > /// Summary description for customer. >>> > /// </summary> >>> > public class control : System.Web.UI.UserControl >>> > { >>> > public static System.Web.UI.WebControls.TextBox txtFirstName; >>> > >>> > private void Page_Load(object sender, System.EventArgs e) >>> > { >>> > //nothing >>> > } >>> > >>> > #region Web Form Designer generated code >>> > //left out for clarity, nothing has >>> > been >>> > altered >>> > #endregion >>> > } >>> > } >>> > >>> > >>> > >>> > Thank you for your help >>> > dave >>> >>> >>> > >
- Next message: Andrew: "Change user control output at runtime?"
- Previous message: Michael Persaud: "Ecards in ASP.NET"
- Next in thread: David A. Coursey: "Re: Accessing members of a user control from the aspx page."
- Reply: David A. Coursey: "Re: Accessing members of a user control from the aspx page."
- Messages sorted by: [ date ] [ thread ]