Click here to Skip to main content
15,881,715 members
Home / Discussions / ASP.NET
   

ASP.NET

 
Questionhow to open page2 from page1 by press button1 on my asp.net program ? Pin
Gali19784-Dec-10 7:57
Gali19784-Dec-10 7:57 
AnswerRe: how to open page2 from page1 by press button1 on my asp.net program ? Pin
TweakBird4-Dec-10 9:51
TweakBird4-Dec-10 9:51 
QuestionPartial postback and update panel problem Pin
Tridip Bhattacharjee4-Dec-10 7:30
professionalTridip Bhattacharjee4-Dec-10 7:30 
AnswerRe: Partial postback and update panel problem Pin
Sandeep Mewara4-Dec-10 7:47
mveSandeep Mewara4-Dec-10 7:47 
GeneralRe: Partial postback and update panel problem Pin
Tridip Bhattacharjee5-Dec-10 4:55
professionalTridip Bhattacharjee5-Dec-10 4:55 
GeneralRe: Partial postback and update panel problem Pin
Sandeep Mewara5-Dec-10 4:55
mveSandeep Mewara5-Dec-10 4:55 
QuestionConfusion regarding c# property Pin
Tridip Bhattacharjee3-Dec-10 23:00
professionalTridip Bhattacharjee3-Dec-10 23:00 
AnswerRe: Confusion regarding c# property Pin
Keith Barrow3-Dec-10 23:55
professionalKeith Barrow3-Dec-10 23:55 
The sample isn't very successful as a basic explanation of accessing viewstate through a method. This is because it adds a dictionary to ViewState, making the code more complicated to understand, as the viewstate iteslf is a a dictionary so you have to workout whether you are dealing with the Viewstate dictionary, or the dictionary inside it. Adding a dictionary to viewstate *is* a pukka thing to do, but it also confuses the explanation IMO. Worse the code adds a new GUID as the key,but doesn't store it on the server side, so it is effectively useless as a key . Take this simplified code, which just stores an integer:


const string MyKey="MeaningOfLife"

private int MeaningOfLife
{
  get { return (int)ViewState[MyKey]; }
  set { ViewState[MyKey] = value; }
}

protected void Page_Load(object sender, EventArgs e)
{
  if (!Page.IsPostBack)
    ViewState.Add("Names", names);
}

protected void btnFoo_Click(object sender, EventArgs e)
{
  if (Page.IsValid)
    Label1.Text= MeaningOfLife;              
}



You only need to add the value once (here before postback): it is available in subsequent postbacks as it is in the viewstate object. The property really just wrappers up accessing the Viewstate dictionary key a bit more neatly than direct access. In your sample code Names.Add(Guid.NewGuid(), txtNewName.Text); the Names property gets the Dictionary added in the page load event, the Add method is called on it to store the new value in the Dictionary inside the [viewstate] Dictionary.

GeneralRe: Confusion regarding c# property Pin
Tridip Bhattacharjee4-Dec-10 4:34
professionalTridip Bhattacharjee4-Dec-10 4:34 
GeneralRe: Confusion regarding c# property Pin
Keith Barrow4-Dec-10 5:26
professionalKeith Barrow4-Dec-10 5:26 
QuestionJQuery unable to find controls on a page [modified] Pin
AndyASPVB3-Dec-10 22:13
AndyASPVB3-Dec-10 22:13 
AnswerRe: JQuery unable to find controls on a page Pin
Not Active4-Dec-10 2:06
mentorNot Active4-Dec-10 2:06 
GeneralRe: JQuery unable to find controls on a page Pin
AndyASPVB4-Dec-10 3:13
AndyASPVB4-Dec-10 3:13 
GeneralRe: JQuery unable to find controls on a page Pin
Not Active4-Dec-10 3:35
mentorNot Active4-Dec-10 3:35 
GeneralRe: JQuery unable to find controls on a page Pin
AndyASPVB4-Dec-10 3:43
AndyASPVB4-Dec-10 3:43 
GeneralRe: JQuery unable to find controls on a page Pin
Not Active4-Dec-10 5:46
mentorNot Active4-Dec-10 5:46 
GeneralRe: JQuery unable to find controls on a page Pin
AndyASPVB6-Dec-10 10:49
AndyASPVB6-Dec-10 10:49 
GeneralRe: JQuery unable to find controls on a page Pin
Not Active6-Dec-10 13:27
mentorNot Active6-Dec-10 13:27 
QuestionASP.Net Newby Question On ListView Pin
Kevin Marois3-Dec-10 7:32
professionalKevin Marois3-Dec-10 7:32 
AnswerRe: ASP.Net Newby Question On ListView Pin
Not Active3-Dec-10 12:36
mentorNot Active3-Dec-10 12:36 
Questionregarding VS2008 IDE Pin
Tridip Bhattacharjee3-Dec-10 6:31
professionalTridip Bhattacharjee3-Dec-10 6:31 
AnswerRe: regarding VS2008 IDE Pin
Brij3-Dec-10 7:42
mentorBrij3-Dec-10 7:42 
GeneralRe: regarding VS2008 IDE Pin
Tridip Bhattacharjee3-Dec-10 23:05
professionalTridip Bhattacharjee3-Dec-10 23:05 
GeneralRe: regarding VS2008 IDE Pin
Brij4-Dec-10 5:14
mentorBrij4-Dec-10 5:14 
QuestionClear session after redirect Pin
Hanzaplast3-Dec-10 5:28
Hanzaplast3-Dec-10 5:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.