Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Custom Control Properties
Message
 
À
01/08/2005 08:57:36
Jim Rieck
Quicken Loans/Rock Financial/Title Sourc
Livonia, Michigan, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 1.1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01037133
Message ID:
01037709
Vues:
21
> Thanks for the response. I've tried using fields and recieved the same results. The code that uses the property is in the constructor. Should it be placed in a different event? If so, which one?

You can't use ViewState in your control if you plan on using it at DesignTime unless you bracket out that code. Accessing ViewState or Session state or anything else that might not e avilalable will cause the control to throw an exception and potentially fail.

There's more info here on how to detect designmode and what to not do in it. basically Render fires in any control.

http://west-wind.com/weblog/posts/189.aspx

and:

http://west-wind.com/weblog/posts/302.aspx

+++ Rick ---

>
>Thanks
>
>Jim
>
>>Hi Jim,
>>
>>Your code won't work like this.
>>
>>Viewstate is not available at design time, so setting hte value causes an error and the value is never stored.
>>
>>You should never hook viewstate (or session values for that matter) to a property directly. Instead have a field backing the property and then do the assignment and retrieval as part of one of the other page events...
>>
>>
>>
>>+++ Rick ---
>>
>>>All,
>>>
>>> I have a custom dropdown list control which has a property that I added called Client Code. If I drag the drop down onto a webform, set a value and run the webform the property is empty. The code I'm using is below.
>>>
>>>Any Ideas?
>>>
>>>
>>>        [Bindable(true),
>>>	Category("Data"),
>>>	DefaultValue("")]
>>>	public string ClientCode
>>>	{
>>>	  get
>>>	    {
>>>		return (ViewState["ClientCode"] == null) ? "BSC" :
>>>		ViewState["ClientCode"].ToString();
>>>	    }
>>>	  set
>>>	    {
>>>		ViewState["ClientCode"] = value;
>>>	    }
>>>        }	
>>>
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform