Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Dynamically Loaded Control and ViewState

Reply
Thread Tools

Dynamically Loaded Control and ViewState

 
 
Joey G
Guest
Posts: n/a
 
      02-17-2004
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><aspanel ID="bx" Runat="server"></aspanel></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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Viewstate for dynamic controls within dynamically loaded usercontr steven scaife ASP .Net 1 10-03-2008 02:44 PM
Managing ViewState of a dynamically created Custom Composite Server Control -(where the original is also dynamically created) dickster ASP .Net Building Controls 0 12-08-2005 09:32 AM
Usercontrol dynamically loaded (in Init method of webcontrol) have viewstate problems Matt Howeson ASP .Net 0 03-18-2005 09:24 PM
Re: Dynamically Loaded UserControl and ViewState S. Justin Gengo ASP .Net 0 02-17-2004 03:50 PM
maintain viewstate using dynamically loaded server controls Thijs ASP .Net Web Controls 2 12-04-2003 10:03 PM



Advertisments