Dynamically Loaded Control and ViewState

Discussion in 'ASP .Net Web Controls' started by Joey G, Feb 17, 2004.

  1. Joey G

    Joey G Guest

    I am having a problem updating the value of a webcontrol after postback when the webcontrol resides in a dynamically loaded usercontrol. In stepping through the code in debug mode, and the dynamically loaded control is being loaded on postback, the value of the control is empty as if it does not have access to the viewstate. That's the first problem (or lack of understanding). The second problem is that when I updated the webcontrol on postback, the value of the webcontrol is reset to the value in the viewstate when all pages are completly loaded. Please help. Here's the code I was testing with
    DEFAULT.ASP
    ----------------------
    <%@ Register TagPrefix="uc1" TagName="WebUserControl" Src="WebUserControl.ascx" %><%@ Page Language="vb" AutoEventWireup="false" Codebehind="default.aspx.vb" Inherits="test._default"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><title>WebForm1</title></HEAD><body MS_POSITIONING="GridLayout"><form id="Form1" method="post" runat="server"><TABLE height="76" width="388"><TR><TD align="right">Dynamic</TD><td><asp:panel ID="bx" Runat="server"></asp:panel></td></TR><TR vAlign="top"><TD align="right">Not Dynamic</TD><td><uc1:WebUserControl id="WebUserControl" runat="server"></uc1:WebUserControl></td></TR><TR><TD align="right"></TD><td><asp:Button ID="sm" Text="Submit" Runat="server"></asp:Button></td></TR></TABLE></form></body></HTML
    --------------------
    DEFAULT.ASPX.V
    -------------------
    Public Class _defaul
    Inherits System.Web.UI.Pag
    Protected WithEvents sm As System.Web.UI.WebControls.Butto
    Protected WithEvents bx As System.Web.UI.WebControls.Pane

    #Region " Web Form Designer Generated Code

    'This call is required by the Web Form Designer
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent(

    End Su

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Ini
    'CODEGEN: This method call is required by the Web Form Designe
    'Do not modify it using the code editor
    End Su

    #End Regio

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa
    Dim ctl As UserContro
    ctl = LoadControl("webUserControl.ascx"
    bx.Controls.Add(ctl
    End Su

    End Clas
    -------------------
    WEBUSERCONTROL.ASC
    -------------------
    <%@ Control Language="vb" AutoEventWireup="false" Codebehind="WebUserControl.ascx.vb" Inherits="test.WebUserControl" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %><asp:TextBox id="txt" runat="server"></asp:TextBox></TD
    ---------------------
    WEBUSERCONTROL.ASCX.V
    ---------------------
    Public MustInherit Class WebUserContro
    Inherits System.Web.UI.UserContro
    Protected WithEvents txt As System.Web.UI.WebControls.TextBo

    #Region " Web Form Designer Generated Code

    'This call is required by the Web Form Designer
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent(

    End Su

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Ini
    'CODEGEN: This method call is required by the Web Form Designe
    'Do not modify it using the code editor
    InitializeComponent(
    End Su

    #End Regio

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa
    If Not IsPostBack The
    txt.Text = "First load
    Els
    txt.Text = "Post load
    End I
    End Su
    End Clas
     
    Joey G, Feb 17, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. S. Justin Gengo

    Re: Dynamically Loaded UserControl and ViewState

    S. Justin Gengo, Feb 17, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,779
    S. Justin Gengo
    Feb 17, 2004
  2. Thanh Nguyen
    Replies:
    0
    Views:
    446
    Thanh Nguyen
    Apr 1, 2004
  3. Matt Howeson
    Replies:
    0
    Views:
    1,742
    Matt Howeson
    Mar 18, 2005
  4. steven scaife
    Replies:
    1
    Views:
    385
    steven scaife
    Oct 3, 2008
  5. Thijs
    Replies:
    2
    Views:
    120
    Brenda
    Dec 4, 2003
Loading...

Share This Page