You're welcome Ankit,
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Ankit Aneja" <ef*****@newsgroups.nospam>
| References: <#U**************@TK2MSFTNGP15.phx.gbl>
<pc**************@TK2MSFTNGXA01.phx.gbl>
| Subject: Re: Problem with adding controls permanently
| Date: Tue, 18 Oct 2005 10:08:53 +0530
| Lines: 248
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <#$**************@TK2MSFTNGP14.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: dsl-upwest-static-146.7.246.61.touchtelindia.net
61.246.7.146
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP14.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:131989
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thanks
| "Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
| news:pc**************@TK2MSFTNGXA01.phx.gbl...
| > Hi Ankit,
| >
| > Welcome to ASPNET newsgroup.
| > From your description, you're wantting to build a asp.net web page which
| > need to dynamically creating some controls and displayed on it on demand
| of
| > user's action(button click postback), yes?
| >
| > As for such scenario, we can consider the following options:
| > 1. As you mentioned, we can precreate all the necessary dynamic controls
| > and hidden them initially and then make them visible later. This will
make
| > the code logic simple.
| >
| > 2. We can dynamically create those controls, however, since dynamically
| > created controls need to be created in each page's request , (int Init
or
| > Load event), we need to put the existing control's count or other intial
| > state in some storage which can be persisted between multiple page
| > request/post backs. And currently, the SessionState, ViewState or
| Database
| > are all possible choice for the storage.
| >
| > Here is a simple demo page which use both SessionState and ViewState to
| > store the dynamic control's count and make us possible to dynaimcally
| > create/delete controls:
| >
| > ========aspx=============
| > <HTML>
| > <HEAD>
| > <title>dynactrl</title>
| > <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
| > <meta name="CODE_LANGUAGE" Content="C#">
| > <meta name="vs_defaultClientScript" content="JavaScript">
| > <meta name="vs_targetSchema"
| > content="http://schemas.microsoft.com/intellisense/ie5">
| > </HEAD>
| > <body>
| > <form id="Form1" method="post" runat="server">
| > <table width="100%">
| > <tr>
| > <td>
| > <asp:PlaceHolder id="phOne" runat="server"></asp:PlaceHolder>
| > </td>
| > </tr>
| > <tr>
| > <td>
| > <asp:Button id="btnAddOne" runat="server" Text="Add"></asp:Button>
| > <asp:Button id="btnRemoveOne" runat="server"
| > Text="Remove"></asp:Button>
| > </td>
| > </tr>
| > <tr>
| > <td>
| > </td>
| > </tr>
| > <tr>
| > <td style="HEIGHT: 23px">
| > <asp:PlaceHolder id="phTwo" runat="server"></asp:PlaceHolder>
| > </td>
| > </tr>
| > <tr>
| > <td>
| > <asp:Button id="btnAddTwo" runat="server" Text="Add"></asp:Button>
| > <asp:Button id="btnRemoveTwo" runat="server"
| > Text="Remove"></asp:Button>
| > </td>
| > </tr>
| > </table>
| > </form>
| > </body>
| > </HTML>
| > ========codebehind========
| > public class dynactrl : System.Web.UI.Page
| > {
| > protected System.Web.UI.WebControls.PlaceHolder phOne;
| > protected System.Web.UI.WebControls.PlaceHolder phTwo;
| > protected System.Web.UI.WebControls.Button btnAddOne;
| > protected System.Web.UI.WebControls.Button btnAddTwo;
| > protected System.Web.UI.WebControls.Button btnRemoveOne;
| > protected System.Web.UI.WebControls.Button btnRemoveTwo;
| >
| > private void Page_Load(object sender, System.EventArgs e)
| > {
| > Init_Dynamic_Controls();
| > }
| >
| > private void Init_Dynamic_Controls()
| > {
| > int i;
| >
| > if(Session["dynacount"] == null)
| > {
| > Session["dynacount"] = 0;
| > }
| >
| > int isession = (int)Session["dynacount"];
| >
| > for(i =0;i<isession;i++)
| > {
| > CheckBox chk = new CheckBox();
| > chk.ID = "chk_" + i;
| > phOne.Controls.Add(chk);
| > }
| >
| > if(ViewState["dynacount"] == null)
| > {
| > ViewState["dynacount"] = 0;
| > }
| >
| > int iviewstate = (int)ViewState["dynacount"];
| > for(i =0;i<iviewstate;i++)
| > {
| > CheckBox chk = new CheckBox();
| > chk.ID = "chk_vs_" + i;
| > phTwo.Controls.Add(chk);
| > }
| > }
| >
| > #region Web Form Designer generated code
| > override protected void OnInit(EventArgs e)
| > {
| > //
| > // CODEGEN: This call is required by the ASP.NET Web Form Designer.
| > //
| > InitializeComponent();
| > base.OnInit(e);
| > }
| >
| > /// <summary>
| > /// Required method for Designer support - do not modify
| > /// the contents of this method with the code editor.
| > /// </summary>
| > private void InitializeComponent()
| > {
| > this.btnAddOne.Click += new System.EventHandler(this.btnAddOne_Click);
| > this.btnAddTwo.Click += new System.EventHandler(this.btnAddTwo_Click);
| > this.btnRemoveOne.Click += new
| > System.EventHandler(this.btnRemoveOne_Click);
| > this.btnRemoveTwo.Click += new
| > System.EventHandler(this.btnRemoveTwo_Click);
| > this.Load += new System.EventHandler(this.Page_Load);
| >
| > }
| > #endregion
| >
| > private void btnAddOne_Click(object sender, System.EventArgs e)
| > {
| > int isession = (int)Session["dynacount"];
| >
| > CheckBox chk = new CheckBox();
| > chk.ID = "chk_" + isession;
| > phOne.Controls.Add(chk);
| >
| > Session["dynacount"] = isession + 1;
| > }
| >
| > private void btnRemoveOne_Click(object sender, System.EventArgs e)
| > {
| > int isession = (int)Session["dynacount"];
| > isession--;
| >
| > CheckBox chk = phOne.FindControl("chk_" + isession) as CheckBox;
| > phOne.Controls.Remove(chk);
| >
| > Session["dynacount"] = isession;
| > }
| >
| > private void btnAddTwo_Click(object sender, System.EventArgs e)
| > {
| > int ivs = (int)ViewState["dynacount"];
| >
| > CheckBox chk = new CheckBox();
| > chk.ID = "chk_vs_" + ivs;
| > phTwo.Controls.Add(chk);
| >
| > ViewState["dynacount"] = ivs +1;
| > }
| >
| > private void btnRemoveTwo_Click(object sender, System.EventArgs e)
| > {
| > int ivs = (int)ViewState["dynacount"];
| > ivs--;
| >
| > CheckBox chk = phTwo.FindControl("chk_vs_" + ivs) as CheckBox;
| > phTwo.Controls.Remove(chk);
| >
| > ViewState["dynacount"] = ivs;
| >
| > }
| > }
| >
| > =====================
| >
| > Hope helps. Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure!
www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| > --------------------
| > | From: "Ankit Aneja" <ef*****@newsgroups.nospam>
| > | Subject: Problem with adding controls permanently
| > | Date: Mon, 17 Oct 2005 15:31:40 +0530
| > | Lines: 16
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| > | Message-ID: <#U**************@TK2MSFTNGP15.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: dsl-upwest-222.11.246.61.touchtelindia.net
| > 61.246.11.222
| > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP15.phx.gbl
| > | Xref: TK2MSFTNGXA01.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:131794
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > |
| > | I have a strange situation and I have no idea how to solve this.
| > | Its a Recruitment Search Page,in the Admin Page, for every button
click
| > | event the Admin Person has to create a checkbox on the users page. So
| > | whenever the Admin person comes to know about the new category in the
| > market
| > | he will be adding as different Sub-Categories for example ABAP, BDC
| > | etc..etc.. on every click event as Checkboxes. And these
| > | controls(checkboxes) should remain on the page forever until we delete
| > them
| > | using another button. By checking them we got to use text value in the
| > | jobsearch. My problem is ... should i already create the checkboxes on
| the
| > | users page and make the Visibility to false and make it true thro the
| > click
| > | event?. Or else do i need to use database ? Can anyone help me in this
| > | please? Or how to solve this?
| > | Thanks in Advance
| > |
| > |
| > |
| >
|
|
|