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. Dynamic Control . does not work until first postback..

Dynamic Control . does not work until first postback..

Scheduled Pinned Locked Moved ASP.NET
design
1 Posts 1 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.
  • F Offline
    F Offline
    Forbiddenx
    wrote on last edited by
    #1

    Ok, here is my design idea.. Textbox is only being used as a test at this point, i have a custom control I will replace it with once I get it working with a basic textbox. I have a list stored in a serialized viewstate. I have a button that when you click it, it creates a item in the viewstate with the buttons id. I have in my PageLoad, code to create a button for each id in the viewstate upon each load.. My view state object..

    namespace CusControls
    {
    [Serializable]
    public class userPramBaseState
    {
    private string _ID;
    public string ID
    {
    get { return _ID; }
    set { _ID = value; }
    }
    }
    }

    Now, this code works, but only after first click.. then all the textboxes retain their values... but the first click.. does nothing.. appears too anyways... but it just does something but nothing works..

    using CusControls;

    public partial class run_reportV2 : basePage
    {

    const string cCusParamList = "CusParamList";
    public List TmpParamList
    {
        get
        {
            if (ViewState\[cCusParamList\] == null)
                ViewState\[cCusParamList\] = new List();
            return (List)ViewState\[cCusParamList\];
        }
    }
    
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        Master.userObj = user;
    }
    
    
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        InitCustomControls();
    }
    
    public void InitCustomControls()
    {
        if (TmpParamList != null)
            foreach (CusControls.userPramBaseState x in TmpParamList)
            {
               TextBox tmpctrl = new TextBox
                {
                    ID = "CUSCTRL" + x.ID
                };
                CusParamControls.Controls.Add(tmpctrl);
            }
    }
           
    public void btnAdd\_Click(object sender, EventArgs e)
    {
        int locid = TmpParamList.Count+1;
        //store control ids into ctrl collection..
        CusControls.userPramBaseState y = new CusControls.userPramBaseState();
        y.ID = "CUSCTRL" + locid;
        TmpParamList.Add(y);
    }
    

    }

    =)

    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