r.r
r.r

Reputation: 7153

create new question if yes/no radio button selected c# asp.net

i have a question:

<div>
    Is hacking good?</div>
    <div>
        <asp:RadioButtonList ID="1question" runat="server" 
            RepeatDirection="Horizontal">
            <asp:ListItem Text="Yes" Value="1"></asp:ListItem>
            <asp:ListItem Text="No" Value="0"></asp:ListItem>
        </asp:RadioButtonList>
    </div>

I want to add dynamicly new question if Yes/No is selected.

if yes/no || 1/0 selected, i'm calling Method GetQuestion(int questionId).. this method returns me a text of next question. this question schould be created dynamicly (javascript) as next. how to create it dynamicly??

How can i do that?

Upvotes: 0

Views: 8342

Answers (1)

Aristos
Aristos

Reputation: 66641

First the new question can be all ready there but hidden, or just create all on the fly.

Let say that is there, but hidden.

<asp:Panel id="pnlSecondQuestion" runat="server" Visible="false" 
                   EnableViewState="false">
    <div>Is hacking ethical?</div>
    <asp:RadioButtonList ID="SecondQuestion" runat="server" 
        RepeatDirection="Horizontal">
        <asp:ListItem Text="Yes" Value="1"></asp:ListItem>
        <asp:ListItem Text="No" Value="0"></asp:ListItem>
    </asp:RadioButtonList>
</asp:Panel>

Now can be hidden of html part and open it with javascript, or totally hidden and open it with the code behind.

  • If you make it Visible="false" then on click of the first question you make autopostback, and you just open this one pnlSecondQuestion.Visible=true In this case to avoid the full page refresh you can use an UpdatePanel warp all your questions.
  • If you make it hidden with css style="display:none", then you make a javasript function that is make it visible when the user click on the first question onclick="return makeitvisible()"

Now if you with to make the full question on the fly, then you use a PlaceHolder, and you dynamically create your question on code behind, but this is a little more dificult.

Hope this help.

Upvotes: 4

Related Questions