tags:

views:

108

answers:

3

I am trying here to create a module linked to a webhosting cart process.

The first step should have a textfield with an "add" button. This button checks the availability of a domain and add it to a list.

The goal here is to basically display the list of domain verified and give proper action as radioboxes (register if it is free, transfert otherwise or point the domain directly).

So basically I check the availability and then add a literal control in a placeholder.

The problem with that is the viewstate (when I step forward and backward I lose the choices I had made with the domains).

the html :

( ... )
        <asp:MultiView ID="mvFlow" runat="server" ActiveViewIndex="0">
      <asp:View ID="vDomain" runat="server" onactivate="vDomain_Activate">

       <asp:TextBox ID="txtDomain" runat="server" style="margin-bottom: 0px" 
        Width="254px"></asp:TextBox>
        &nbsp;<asp:Button ID="domainAdd" runat="server" onclick="domainAdd_Click" 
        style="height: 26px" Text="Ajouter" />
       &nbsp;<br />
       <br />
       <asp:PlaceHolder ID="phDomainResults" runat="server"></asp:PlaceHolder>
       <br />
       <br />
       <asp:LinkButton ID="lbDomainSkip" runat="server" onclick="lbDomainSkip_Click">Prochaine 
       étape »</asp:LinkButton>

      </asp:View>
( ... )

behind it's basically something like this :

lt.Text =

     "<dl>" +
      "<dt><strong>" + txtDomain.Text + "</strong> <span style='color:green;'>Le domaine est disponible</span></dt>" +
      "<dd><input type='radio' name='" + txtDomain.Text.Replace('.', '_') + "_action' value='register' /> Register</dd>" +
      "<dd><input type='radio' name='" + txtDomain.Text.Replace('.', '_') + "_action' value='transfert' disabled='disabled' /> Transfert</dd>" +
      "<dd><input type='radio' name='" + txtDomain.Text.Replace('.', '_') + "_action' value='point' /> Point</dd>" +
     "</dl>";

There must be possible to make things more logical and easy ?

Following suggestion I did this :

LiteralControl lt = new LiteralControl();
RadioButtonList rl = new RadioButtonList();

lt.Text = "<strong>" + txtDomain.Text + "</strong> <span style='color:green;'>Le domaine est disponible</span>";
rl.Items.Add(new ListItem { Enabled = true, Selected = true, Text = "Enregistrement", Value = "register" });
rl.Items.Add(new ListItem { Enabled = false, Selected = false, Text = "Transfert", Value = "transfert" });
rl.Items.Add(new ListItem { Enabled = true, Selected = false, Text = "Pointer moi même", Value = "point" });
//phDomainResults is a PlaceHolder in the page
phDomainResults.Controls.Add(lt);
phDomainResults.Controls.Add(rl);

Doesn't seem to work more...

A: 

If need to use view state then you are correct, you cannot use a literal. (Or more specifically you could but it would be pretty cumbersome.

You should probably generate an asp RadioButtonList element on the fly and add that to your place holder. Your page will be able to remember the RadioButtonList in viewstate.

brendan
Tried, doesn't seem to save the List itself ..
Erick
A: 

I would store the relevant information in the ViewState collection in your code behind and on every page load clear the place holder values and re-render and add the literals just as you are now. This way you don't have to worry yourself with what ASP.Net will and won't save.

Spencer Ruport
+1  A: 

ASP.NET is saving the view state just fine: it's preserving the contents of the literal, just as it should. However, the content of the literal is just the markup (the <dl> with the radio buttons), not what the user might have done to those buttons.

Because you are dynamically adding the radio buttons to the HTML, the ASP.NET page doesn't "know" about them.

Instead of spitting out radio buttons in a Literal control, you might try using a RadioButtonList instead.

Matt Peterson
Doesn't seem to work, when I go back the RadioButtonList have disapeared.
Erick