Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
microsoft.public.dotnet.framework.aspnet.webcontrols
Dynamically Loaded Control and ViewState
JHG
2/17/2004 3:16:00 PM
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...
%><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
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Dynamically Loaded Control and ViewState
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password