CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums

ASP.NET Web Hosting – 3 Months Free!



Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 1/2/2004 11:50:12 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 18 Views: 20 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
19 Items, 1 Pages 1 |< << Go >> >|
troy23
Asp.Net User
Viewstate Expert Needed1/2/2004 11:50:12 PM

0/0

Viewstate is being lost between calls. I thought it would be a global value. Here is the scenario:

Container form contains a button event to send a path string to a user control as follows

Private Sub btnDept_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDept.Click
Me.ucAdminComboUpdate.xml_path = "../xml/Department.xml"

End Sub


The user control accepts the string and sets the viewstate in a property procedure. However , when the code returns to the user control the viewstate is lost and the 'BindData' procedure cannot load the file as it has no path from the viewstate.


User control

Public Property xml_path() As String
Get
Return viewstate("xml_path")
End Get
Set(ByVal Value As String)
viewstate("xml_path") = Value
End Set
End Property


Private Sub BindData()

Dim doc As New XmlDocument

' Response.Write(xml_path)


If Me.IsPostBack = True Then

doc.Load(Server.MapPath(xml_path))

End If
End Sub

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender

BindData()

End Sub
NetProfit
Asp.Net User
Re: Viewstate Expert Needed1/3/2004 12:33:21 AM

0/0


Are you creating this user control on your page declaratively (at design time), or are you loading it dynamically at runtime?

I'm guessing that you are loading it dynamically at runtime. If that's the case, it should be loaded before or during Page_Load so that its viewstate can be restored by the page once it is added to the control tree.

If you're looking for more help, please post the code from your .aspx page where you load the control.

Jamie Kindred, CGA, MCSD
Senior Solutions Architect
TSi Auto Solutions
master4eva
Asp.Net User
Re: Viewstate Expert Needed1/3/2004 7:53:32 AM

0/0

For view state to be restored correctly as well (if you are injecting server controls dynamically which I also suspect) is to have a static ID to the new server control.
-- Justin Lovell
troy23
Asp.Net User
Re: Viewstate Expert Needed1/3/2004 3:14:17 PM

0/0

Thanks for replying. Below is the declaration of the user control within the html and code behind. I am unsure how it can be loaded during the page load event.

<%@ Register TagPrefix="uc1" TagName="AdminComboUpdates" Src="AdminComboUpdates.ascx" %>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="admin.aspx.vb" Inherits="pims.admin"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>admin</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="flowLayout">
<form id="Form1" method="post" runat="server">
<uc1:AdminComboUpdates id="AdminComboUpdates1" runat="server"></uc1:AdminComboUpdates>
<table cellSpacing="0" cellPadding="0" width="100" border="2" style="WIDTH: 600px; HEIGHT: 14px">
<tr>
<td style="HEIGHT: 38px"></td>
<td style="HEIGHT: 38px"></td>
<td style="WIDTH: 101px; HEIGHT: 38px"></td>
<td style="WIDTH: 103px; HEIGHT: 38px"><asp:Label id="lblDept" runat="server" Width="86px" Height="21px">Department</asp:Label></td>
<td style="WIDTH: 2px; HEIGHT: 38px"><asp:Button id="btnDept" runat="server" Width="30px" Height="25px"></asp:Button></td>
<td style="WIDTH: 45px; HEIGHT: 38px"></td>
<td style="HEIGHT: 38px"></td>
<td style="HEIGHT: 38px"></td>
<td style="HEIGHT: 38px"></td>
</tr>
<tr>
<td style="HEIGHT: 38px"></td>
<td style="HEIGHT: 38px"></td>
<td style="WIDTH: 101px; HEIGHT: 38px"></td>
<td style="WIDTH: 103px; HEIGHT: 38px"><asp:Label id="lblEthnic" runat="server" Width="125px" Height="21px">Ethnic Group</asp:Label></td>
<td style="WIDTH: 2px; HEIGHT: 38px"><asp:Button id="btnEthnic" runat="server" Width="30px" Height="25px"></asp:Button></td>
<td style="WIDTH: 45px; HEIGHT: 38px"></td>
<td style="HEIGHT: 38px"></td>
<td style="HEIGHT: 38px"></td>
<td style="HEIGHT: 38px"></td>
</tr>
</table>
</form>
</body>
</HTML>


Public Class admin
Inherits System.Web.UI.Page


Protected WithEvents ucAdminComboUpdate As New pims.AdminComboUpdate




Edit by moderator - NetProfit: Added < code></ code> tags.
troy23
Asp.Net User
Re: Viewstate Expert Needed1/3/2004 3:37:30 PM

0/0

Thanks for your reply also. Could you pls explain further with any code samples as I am a newbie at this and my books don't seem to cover the topic in much depth. Thank you.
master4eva
Asp.Net User
Re: Viewstate Expert Needed1/3/2004 6:02:39 PM

0/0

My suggestion and the other poster's suggestion is void in your case because the controls do have a static ID. I do see the problem in your code. With this code-behind line:

Protected WithEvents ucAdminComboUpdate As New pims.AdminComboUpdate

Change it to this:

Protected WithEvents ucAdminComboUpdate

-- Justin Lovell
troy23
Asp.Net User
Re: Viewstate Expert Needed1/4/2004 10:06:58 AM

0/0

Thanks for the reply. I tried your suggestion, but I get an error saying "with events must have an AS clause".

master4eva
Asp.Net User
Re: Viewstate Expert Needed1/4/2004 5:52:19 PM

0/0

/me Hit self on head.

Sorry for that, my head was not thinking when I wrote that post (and partially, I am a C# guy) :) . The line is supposed to look like:

Protected WithEvents ucAdminComboUpdate As pims.AdminComboUpdate

-- Justin Lovell
NetProfit
Asp.Net User
Re: Viewstate Expert Needed1/4/2004 5:57:26 PM

0/0

Try:

Protected WithEvents ucAdminComboUpdate As pims.AdminComboUpdate

or:

Protected ucAdminComboUpdate As pims.AdminComboUpdate

Jamie Kindred, CGA, MCSD
Senior Solutions Architect
TSi Auto Solutions
troy23
Asp.Net User
Re: Viewstate Expert Needed1/4/2004 6:08:53 PM

0/0

Thanks again...having tried the line of code in both your and the next posting suggestion I get an error of "Object reference not set to an instance of an object" at the line.

Me.ucAdminComboUpdate.xml_path = "../xml/Department.xml"
NetProfit
Asp.Net User
Re: Viewstate Expert Needed1/4/2004 6:20:14 PM

0/0

Where did you put this line?

Make sure it is outside of any sub procedure.

Make sure the variable name is identical to the ID in your server tag for your user control.
Jamie Kindred, CGA, MCSD
Senior Solutions Architect
TSi Auto Solutions
troy23
Asp.Net User
Re: Viewstate Expert Needed1/4/2004 6:39:37 PM

0/0

That's great it works now. Seems like I had not used the server ID of the user control in the declaration. I've noticed in some cases people tend to use the Load command for loading user conrols...is there a particular reason for this and would it make life easier for what I am doing? Thanks again for your help
troy23
Asp.Net User
Re: Viewstate Expert Needed1/4/2004 6:41:11 PM

0/0

Thanks it's ok now. Your and the other posters suggestions worked nicely. Just needed to use the server ID of the user control in the declaration
NetProfit
Asp.Net User
Re: Viewstate Expert Needed1/5/2004 1:14:31 AM

0/0


The LoadControl method is good for situations where you need to load certain user controls dynamically depending on the scenario. If this is not a requirement it is better (ie: more simplified) to create them declaritively on your form at design time.

Glad it's working ok for you now. :)

Cheers,

Jamie Kindred, CGA, MCSD
Senior Solutions Architect
TSi Auto Solutions
tine2502
Asp.Net User
Re: Viewstate Expert Needed1/6/2004 11:29:15 AM

0/0

Hi,
could someone of you put a solution in c#, too? I'm having some problems with that, too, even if i load my controls in the beginnings and set them visible / unvisible. Perhaps its a problem that i have a control in another control?
Thanks!
master4eva
Asp.Net User
Re: Viewstate Expert Needed1/6/2004 1:01:19 PM

0/0

This VB?

Protected WithEvents ucAdminComboUpdate As pims.AdminComboUpdate

If it is, it is in C#:

protected pims.AdminComboUpdate ucAdminComboUpdate;

-- Justin Lovell
Alan Wardle
Asp.Net User
Re: Viewstate Expert Needed1/14/2004 5:07:15 PM

0/0

Hi Jamie,
I'm sorry to bother you with this, but looking at your previous posts I thought you'd probably know the answere to my problem.

I'm setting Viewstate in a control event. After posting, in the Page_Load event I find
that the ViewState does not show the correct value. If the page is posted again, the
correct value IS shown.
How do I recover the correct control event ViewState on the first Page_Load, Thanks.

As an example of problem, here's a simple example which demonstrates it

<%@ Page Language="VB" %>

<script runat="server">

Sub Page_Load
ViewState("PageLoad")+=1
lblLoad.text="Load :" & ViewState("PageLoad")
lblClick.text="Click :" & ViewState("Function")
End Sub

Sub But_Click(s as Object, e as EventArgs)
ViewState("Function")+=1
End Sub

</script>


<html>
<head><title>Bug Test</title></head>

<form runat="Server">

<asp:Label
ID="lblLoad"
runat="Server"/>
<br><br>

<asp:Label
ID="lblClick"
runat="Server"/>
<br><br>

<asp:Button
OnClick="But_Click"
Text="AddToFunctionViewState"
runat="server"/>
<br><br>

<asp:Button
id="But2"
Text="AddToPageLoadViewState"
runat="server"/>
</form>
</body>
</html>

Thanks a lot
NetProfit
Asp.Net User
Re: Viewstate Expert Needed1/15/2004 3:16:50 AM

0/0


Remember that a control event, such as a button click event, fires after the page load event. We cannot change the order of these events, they are determined by the page framework. I am guessing that you are seeing this problem with ViewState("Function"). Since page_load is executing before your button click, you are indeed seeing the old value during page load. After your button click event executes, you will notice that ViewState("Function") has the new value. Try putting this line in your button click event handler after the line that updates the VeiwState:

lblClick.text="Click :" & ViewState("Function")


If you need more control over the ViewState of this particular control, so that it is available during the page_load event, you will need to set the VeiwState variable earlier on during the page life cycle, or build your own server control that implements the IStateManager interface. The first option is limited but simple, the second option is flexible but somewhat complex.

BTW: Please enclose your code inside of < code></ code> tags to keep the formatting nice! ;)

Hope this is of some help.

Jamie Kindred, CGA, MCSD
Senior Solutions Architect
TSi Auto Solutions
Alan Wardle
Asp.Net User
Re: Viewstate Expert Needed1/16/2004 1:07:17 PM

0/0

Now that I appreciate the order of events, my page goes from SQL Server record insert to
update with no problems, nice one.
19 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Expert ASP.NET 2.0 Advanced Application Design: Advanced Application Design Authors: Dominic Selly, Andrew Troelsen, Tom Barnaby, Pages: 459, Published: 2005
Pro ASP.NET 2.0 in VB 2005: From Professional to Expert Authors: Laurence Moroney, Matthew MacDonald, Pages: 1253, Published: 2006
Beginning ASP.NET 3.5 in VB 9.0: From Novice to Professional Authors: Matthew MacDonald, Pages: 1149, Published: 2007
Expert F# Authors: Don Syme, Adam Granicz, Antonio Cisternino, Pages: 609, Published: 2007
Expert Spring MVC and Web Flow Authors: Seth Ladd, Darren Davison, Steven Devijver, Keith Donald, Colin Yates, Pages: 403, Published: 2006

Web:
RT - 24/7 English-language news channel : News : RT Expert View ... Sep 19, 2008 ... RT Expert View: state borders vs. self-determination. This week we ask experts to comment on one of the basic contradictions of ...
Bay View State Park Travel Guide | Away.com Away.com's Bay View State Park travel guides provide information on hotels, ... Expert Rated & Recommended. 4.0. All Bay View State Park Hotels » ...
ViewState: All You Wanted to Know: ASP Alliance This article looks at what ViewState is NOT and what it is, ... This article provided the evidence that I needed to begin investigating an alternative ...
How to pass ViewState value from web form page to web user control ... Hello Expert, I face the problem where i cant get d value of my ViewState in my user control page as the viewstate is assign the value in my web form page.
How to save an array to viewstate in asp.net? Hi Expert, I have several arrays need to be saved to viewstate. for example, client_id(i) lname(i) fname(i) I got the total i as totalcount from...
Validation of viewstate MAC failed error in asp.net? (asp.net ... HttpException: Validation of viewstate MAC failed Do you know what that means and how to correct ... and points have been rewarded to the following experts: ...
Changing page position of Viewstate for SEO well-optimised page a large viewstate can be detrimental to it's ... Upon talking with our HTML expert, he was able to shed light on some of ...
Inside Microsoft: ASP.NET ViewState Inside Microsoft: ASP.NET ViewState .... They can choose from beginner, intermediate, and expert and we will modify some parts of the site that they use ...
ViewState is Corrupt or Invalid for this page - ExtremeExperts NET runs a message authentication check (MAC) on the view state of the page when the page is posted back from the client. This check determines if the view ...
Re: viewstate gets too big sure you can, viewstate is only needed as a way to preserve the state of the ... Upon talking with our HTML expert, he was able to shed light on some of my ...




Search This Site:










porting msde database

a module similar to control gallery

namespace not found error after deployment

what is the tool?

.net webcontrols

multilingual portal using ressources

getting error : server error in '/' application

novice coder looking for education materials for ibuyspy

tab to modules link ?

installing a dotnetnuke module in the portal starter kit

ibuyspy portal problem with vs2003.net

not able to login portal starter kit (vbvs) on winxp.

installation problem

adding a custom module (milestones)

the trouble with tribbles [err modules]

adding a new portal

controling centerpane content from leftpane menu?

portal authentication

trying to get a submit button to work on the home page

application_beginrequest performance impact

opening ibuyspy portalsource code with visual studio.net

compile error

security issues?

tree view

what is the code snippet mean in the web.config?

content manager

paypal ipn handler for ibs vb

help: question about using the applications

portal security bug

connection failed during setup

  Privacy | Contact Us
All Times Are GMT