Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Help with View State/Postback! Texbox data does not save!Help with View State/Postback! Texbox data does not save!
Previous
 
Next
New Post
4/26/2007 4:59 PM
 

 I am trying to a very simple page using the Wizard Control but when the user inputs data into the auto generated textboxes, the data is not preserved on the final step.

 

I think is a matter of preserving the user state somehow. I come from ASP background but this ASP.NET on how the events and post backs is driving me crazy.

 

I already tried all the different events. How can I take values from a previous post back?

 

 

 

newProjectWizard.aspx 

 

<%@ Page Language ="C#" AutoEventWireup="true" CodeFile="newProjectWizard.aspx.cs" Inherits="postbackTest" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

< form id="form1" runat="server">

<div>

<asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="0" >

< WizardSteps>

<asp:WizardStep ID="WizardStep1" runat="server" Title="Enter number of inputs">

&nbsp;&nbsp;

<asp:DropDownList ID ="ddlCategories" runat="server">

<asp:ListItem></asp:ListItem>

<asp:ListItem>1</ asp:ListItem>

<asp:ListItem>2</asp:ListItem>

<asp:ListItem Selected="True">3 </asp:ListItem>

<asp:ListItem>4</asp:ListItem>

<asp:ListItem>5 </asp:ListItem>

<asp:ListItem>6</asp:ListItem>

<asp:ListItem>7 </asp:ListItem>

<asp:ListItem>8</asp:ListItem>

<asp:ListItem>9 </asp:ListItem>

<asp:ListItem>10</asp:ListItem>

</asp:DropDownList>

</asp:WizardStep>

<asp:WizardStep ID="WizardStep2" runat="server" Title="Enter data to inputs" >

&nbsp;

<asp :PlaceHolder ID="PlaceHolder1" runat="server" OnLoad="generateTextboxes"></asp:PlaceHolder>

</asp:WizardStep>

<asp:WizardStep ID="WizardStep3" runat="server" Title="Display user input" >

<asp:PlaceHolder ID="PlaceHolder2" runat="server" OnLoad="generateLabels"></asp:PlaceHolder>

</ asp:WizardStep>

</WizardSteps>

</asp:Wizard>

 

</div>

</form>

</body>

</html>

 

newProjectWizard.aspx.cs 

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

 

public partial class postbackTest : System.Web.UI.Page{

 

     public void generateTextboxes(object sender, EventArgs e){

          int numberOfTextboxesToBeCreated = Convert.ToInt16(ddlCategories.SelectedValue);

          for (int i = 0; i < numberOfTextboxesToBeCreated; i++) {

               TextBox tb = new TextBox();

               tb.Text = "change me " + i;

               PlaceHolder1.Controls.Add(tb);

          }

     }

 

 

     public void generateLabels(object sender, EventArgs e) {

          int numberOfTextboxesToBeCreated = Convert.ToInt16(ddlCategories.SelectedValue);

          for (int i = 0; i < numberOfTextboxesToBeCreated; i++) {

               Label l = new Label();

               TextBox tb = (TextBox)PlaceHolder1.Controls[i];

               l.Text = "[" + tb.Text + "]";

               PlaceHolder2.Controls.Add(l);

          }

     }

}

 

 

 
New Post
4/27/2007 4:48 AM
 

The ViewState gets only values of controls that are loaded after the Page OnLoad event. Controls that are in the ASPX pages are loaded automatically,  if you add some controls dynamically, you need to reload them dynamically on the OnLoad event of the page to be able to use the ViewState.

So basically the value of the dropdown is not yet known in the other control load events, you should use the OnRender event insteed to make it :-))

 

 

 
New Post
4/27/2007 11:05 AM
 
Good point lolo.

Another way is to manually add the values to the viewstate, although it will break away from your current framework.

Add to the ViewState:
ViewState.Add("ControlName", control.Text);

Get from the ViewState:

control.Text = (string)ViewState["ControlName"];

or

control.Text = Convert.ToString(ViewState["ControlName"]);

or

control.Text = ViewState["ControlName"].ToString();

Cheers!
John Valentine
http://www.webinnovationsystems.com
 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Help with View State/Postback! Texbox data does not save!Help with View State/Postback! Texbox data does not save!


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out