Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Programmatically add textbox control with incrementing id

Reply
Thread Tools

Programmatically add textbox control with incrementing id

 
 
nLL
Guest
Posts: n/a
 
      03-12-2009
Hi everyone, I am developing a simple poll/voting application and i need
to programmatically add choices/options as user clicks to add new choice
button.

I have
Poll question text box
First poll answer/choice with id choice1 in Choices Placeholder
Add new choice button.

When add new choice button clicked, i want to get id of last textbox
control in Choice Placeholder and add new textbox control with
incremented id.

here is the code side of it

-----------------
Poll question:
<asp:TextBox ID="PollQuestionText" runat="server"></asp:TextBox><br />
<asplaceHolder ID="PollAnswers" runat="server">
<asp:Label ID="PollAnswerLabel1" runat="server" Text="Choice
1"></asp:Label>: <asp:TextBox ID="PollAnswer1" runat="server"></asp:TextBox>
<!-- INSERT NEW TEXTBOX CONTROL HERE AS ADD NEW BUTTON CLICKED-->
</asplaceHolder>

<asp:Button ID="addChoiceButton" runat="server" Text="Add new choice"
onclick="addChoiceButton_Click" />
<asp:Button ID="SaveButton" runat="server" Text="Save" />
--------------------------------------------------

This will be a mobile web app so I can't use javascript.
Could any one point me to the right direction?

Thanks


 
Reply With Quote
 
 
 
 
nLL
Guest
Posts: n/a
 
      03-12-2009
got it with

protected void addChoiceButton_Click(object sender, EventArgs e)
{
addChoiceButton.Visible = false;
ChoicecountDropDownList.Visible = false;
HyperLinkReload.Visible = true;
HyperLinkReload.NavigateUrl = Request.FilePath +"?"+
Request.QueryString;

int numtextboxes =
System.Convert.ToInt32(ChoicecountDropDownList.Sel ectedItem.Value);
for (int i = 1; i <= numtextboxes; i++)
{
TextBox myTextbox = new TextBox();
myTextbox.ID = "Choice" + i.ToString();

Label myTextboxLabel = new Label();
myTextboxLabel.Text = "Choice " + i.ToString();
myTextboxLabel.ID = "Label" + i.ToString();
ChoicesPlaceHolder.Controls.Add(myTextboxLabel);
ChoicesPlaceHolder.Controls.Add(new LiteralControl(": "));
ChoicesPlaceHolder.Controls.Add(myTextbox);
ChoicesPlaceHolder.Controls.Add(new LiteralControl("<br />"));
}


nLL wrote:
> Hi everyone, I am developing a simple poll/voting application and i need
> to programmatically add choices/options as user clicks to add new choice
> button.
>
> I have
> Poll question text box
> First poll answer/choice with id choice1 in Choices Placeholder
> Add new choice button.
>
> When add new choice button clicked, i want to get id of last textbox
> control in Choice Placeholder and add new textbox control with
> incremented id.
>
> here is the code side of it
>
> -----------------
> Poll question:
> <asp:TextBox ID="PollQuestionText" runat="server"></asp:TextBox><br />
> <asplaceHolder ID="PollAnswers" runat="server">
> <asp:Label ID="PollAnswerLabel1" runat="server" Text="Choice
> 1"></asp:Label>: <asp:TextBox ID="PollAnswer1"
> runat="server"></asp:TextBox>
> <!-- INSERT NEW TEXTBOX CONTROL HERE AS ADD NEW BUTTON CLICKED-->
> </asplaceHolder>
>
> <asp:Button ID="addChoiceButton" runat="server" Text="Add new choice"
> onclick="addChoiceButton_Click" />
> <asp:Button ID="SaveButton" runat="server" Text="Save" />
> --------------------------------------------------
>
> This will be a mobile web app so I can't use javascript.
> Could any one point me to the right direction?
>
> Thanks
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DetailsView programmatically Add Custom Control Peter Pan ASP .Net 0 04-13-2009 11:39 AM
Programmatically add textbox control with incrementing id nLL ASP .Net 2 03-12-2009 12:13 PM
this.Controls.Add(Control) Does Not Add Control to child collection (this.Controls.Count == 0) Chad Scharf ASP .Net 3 10-18-2007 03:53 PM
Add Annotation (textbox) to TIFF(MODI) programmatically jrpe Java 0 08-24-2006 08:08 AM
Re: VERY STRANGE BUG? Adding a textbox control causes other textbox control to fail??? S. Justin Gengo ASP .Net 0 07-16-2003 06:51 PM



Advertisments