asp.net - ASP .NET Wizard Control and View State -


i have form 3 wizard steps, , when click button dynamically add text boxes, works fine, when go next step , click on add add more text boxes, automatically adds text boxes previous steps , continues add if keep click on it.

how prevent happening.

private list controlslist { { if (viewstate["controls"] == null) { viewstate["controls"] = new list(); } return (list)viewstate["controls"]; } }

private int nextid {         {         return controlslist.count + 1;     } }   protected override void loadviewstate(object savedstate) {      string section = wizard1.activestep.id;     int sectionnum = wizard1.activestepindex;      var control = wizard1.activestep.findcontrol("place" + sectionnum) placeholder;      base.loadviewstate(savedstate);      int count = 0;     foreach (string txtid in controlslist)     {         if (count == 0)         {             control.controls.add(new literalcontrol("<tr>"));         }         textbox txt = new textbox();         control.controls.add(new literalcontrol("<td>"));         txt.id = txtid;         control.controls.add(txt);         control.controls.add(new literalcontrol("</td>"));          count = count + 1;         if (count == 3)         {             control.controls.add(new literalcontrol("</tr>"));             count = 0;         }      } }   protected void addcontrolbutton_click(object sender, eventargs e) {       string section = wizard1.activestep.id;     int sectionnum = wizard1.activestepindex;      var control = wizard1.activestep.findcontrol("place" + sectionnum) placeholder;      textbox txt1 = new textbox();     textbox txt2 = new textbox();     textbox txt3 = new textbox();       txt1.id = section.tostring() + "size" + nextid.tostring();     control.controls.add(new literalcontrol("<td>"));     control.controls.add(txt1);     control.controls.add(new literalcontrol("</td>"));     controlslist.add(txt1.id);      txt2.id = section.tostring() + "description" + nextid.tostring();     control.controls.add(new literalcontrol("<td>"));     control.controls.add(txt2);     control.controls.add(new literalcontrol("</td>"));     controlslist.add(txt2.id);      txt3.id = section.tostring() + "quantity" + nextid.tostring();     control.controls.add(new literalcontrol("<td>"));     control.controls.add(txt3);     control.controls.add(new literalcontrol("</td></tr>"));     controlslist.add(txt3.id); 

}

you storing of dynamic textboxes in viewstate , controlslist property getter returning whole list when building textboxes.

my recommendation use session cache instead of viewstate, because allow differentiate textbox controls each of wizard steps, this:

session["wizardstep1"] = listoftextboxesfromstep1; session["wizardstep2"] = listoftextboxesfromstep2; session["wizardstep3"] = listoftextboxesfromstep3; 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -