Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. runtime generation of controls and their text

runtime generation of controls and their text

Scheduled Pinned Locked Moved ASP.NET
question
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MalarGayu
    wrote on last edited by
    #1

    hi friends i have a button on the click of which i get textboxes.. say at one time i want 2 textboxes and the next time i want 3 textboxes and may be next time i want 1 textbox ... and then i choose anyoption from the dropdownlist say the options in the dropdownlist is: as checkboxes as radiobuttons as a select menu dont display it and i choose any one may be checkbox or may be radio buttons and click on another button(save button) now on my new aspx page i need the options entered in the textboxes to be accompanied by the options from the dropdownlist say checkbox or radiobuttons hope you got my question now... K.Gayathri

    N 1 Reply Last reply
    0
    • M MalarGayu

      hi friends i have a button on the click of which i get textboxes.. say at one time i want 2 textboxes and the next time i want 3 textboxes and may be next time i want 1 textbox ... and then i choose anyoption from the dropdownlist say the options in the dropdownlist is: as checkboxes as radiobuttons as a select menu dont display it and i choose any one may be checkbox or may be radio buttons and click on another button(save button) now on my new aspx page i need the options entered in the textboxes to be accompanied by the options from the dropdownlist say checkbox or radiobuttons hope you got my question now... K.Gayathri

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      What is your question?


      No comment

      M 1 Reply Last reply
      0
      • N Not Active

        What is your question?


        No comment

        M Offline
        M Offline
        MalarGayu
        wrote on last edited by
        #3

        i have a button on the click of which textboxes will appear and i have a dropdownlist which has the options as: as checkboxes as radiobuttons as a select menu dont display it if i click the button say 5 times 5 textboxes will appear and i type in one,two,three,four,five and choose radiobuttons from the dropdownlist and click save button in that page it should redirect to another aspx page where i will have one,two,three,four,five along with radiobuttons for each... so how to do it... K.Gayathri

        N 1 Reply Last reply
        0
        • M MalarGayu

          i have a button on the click of which textboxes will appear and i have a dropdownlist which has the options as: as checkboxes as radiobuttons as a select menu dont display it if i click the button say 5 times 5 textboxes will appear and i type in one,two,three,four,five and choose radiobuttons from the dropdownlist and click save button in that page it should redirect to another aspx page where i will have one,two,three,four,five along with radiobuttons for each... so how to do it... K.Gayathri

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          You can create controls in your code and add them to the page dynamically This assumes you are passing the number of controls to create and the type of control (as an int) to the page.

          void CreateControls()
          {
          int numberOfControls = Request["numberOfCtrls"];
          switch(Convert.ToInt32(Request["ctrlType"]))
          {
          case 1:
          for(int x = 0; x < numberOfControls; x++)
          {
          RadioButton ctrl = new RadioButton();
          ... set any properties ...
          Controls.Add(ctrl);
          }
          break;
          case 2:
          ...
          }
          }


          No comment

          M 1 Reply Last reply
          0
          • N Not Active

            You can create controls in your code and add them to the page dynamically This assumes you are passing the number of controls to create and the type of control (as an int) to the page.

            void CreateControls()
            {
            int numberOfControls = Request["numberOfCtrls"];
            switch(Convert.ToInt32(Request["ctrlType"]))
            {
            case 1:
            for(int x = 0; x < numberOfControls; x++)
            {
            RadioButton ctrl = new RadioButton();
            ... set any properties ...
            Controls.Add(ctrl);
            }
            break;
            case 2:
            ...
            }
            }


            No comment

            M Offline
            M Offline
            MalarGayu
            wrote on last edited by
            #5

            hi friends i have created the controls but dont know how to get the value from such controls can anyone help me plz... //code to create the dynamic textboxes protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { Session["Count"] = "0"; } } protected void lnkAddGroup_Click(object sender, EventArgs e) { int i = Convert.ToInt32(Session["Count"].ToString()); int k = 0; for (k = 0; k <= i; k++) { TextBox txt = new TextBox(); txt.ID = "DynamiceTextbox" + Convert.ToString(k); //txt.Text = "" ; ImageButton img = new ImageButton(); img.ID = "DynamicDeletebutton" + Convert.ToString(k); img.ImageUrl = "~Images/delete_icon.jpg"; HtmlGenericControl lineBreak = new HtmlGenericControl("br"); PHGroupName.Controls.Add(txt); PHGroupName.Controls.Add(img); PHGroupName.Controls.Add(lineBreak); Session["Count"] = Convert.ToString(Convert.ToInt32(k + 1)); } } PHGroupName is the placeholder name.... K.Gayathri

            M 1 Reply Last reply
            0
            • M MalarGayu

              hi friends i have created the controls but dont know how to get the value from such controls can anyone help me plz... //code to create the dynamic textboxes protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { Session["Count"] = "0"; } } protected void lnkAddGroup_Click(object sender, EventArgs e) { int i = Convert.ToInt32(Session["Count"].ToString()); int k = 0; for (k = 0; k <= i; k++) { TextBox txt = new TextBox(); txt.ID = "DynamiceTextbox" + Convert.ToString(k); //txt.Text = "" ; ImageButton img = new ImageButton(); img.ID = "DynamicDeletebutton" + Convert.ToString(k); img.ImageUrl = "~Images/delete_icon.jpg"; HtmlGenericControl lineBreak = new HtmlGenericControl("br"); PHGroupName.Controls.Add(txt); PHGroupName.Controls.Add(img); PHGroupName.Controls.Add(lineBreak); Session["Count"] = Convert.ToString(Convert.ToInt32(k + 1)); } } PHGroupName is the placeholder name.... K.Gayathri

              M Offline
              M Offline
              MalarGayu
              wrote on last edited by
              #6

              hi friends i am using the following code: int i = Convert.ToInt32(Session["Count"].ToString()); int k = 0; string[] strTextBoxValues = new string[] { }; for (k = 0; k <= i - 1; k++) { string textboxval = "DynamicTextbox" + Convert.ToString(k); TextBox textval = (TextBox)this.Page.FindControl(textboxval); textval.ID = textboxval; Response.Write(textval.Text); } but the findcontrol method returns null....and any one to help me in this issue as i am stuck in my work... K.Gayathri

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups