Results 1 to 7 of 7

Thread: [RESOLVED] runtime control disappear when postback

  1. #1

    Thread Starter
    Fanatic Member popskie's Avatar
    Join Date
    Jul 2005
    Location
    In my chair
    Posts
    666

    Resolved [RESOLVED] runtime control disappear when postback

    hi,

    pls forgive me Im a newbie to asp.net . this is just 2nd day of teaching my self in asp.net.

    I have a web application using c#. I have 2 controls during button1 and button2. When I click button1 it create a textbox and display to the page but i click button2 even there's no code behind. The textbox disapper. Anyone can give me right direction or just give a code.

    Thanks,

    Popskie

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: runtime control disappear when postback

    This happens because when you click Button2 the Page is posted back to the server and a new page is rendered on the client. I would suggest puttin the control creation code in the Page_load event rather than commandbutton's click event.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  3. #3

  4. #4

    Thread Starter
    Fanatic Member popskie's Avatar
    Join Date
    Jul 2005
    Location
    In my chair
    Posts
    666

    Re: runtime control disappear when postback

    hi,
    this is how add control to my page.

    VB Code:
    1. TextBox t = new TextBox();
    2.                 t.Text = "Hi Hello ";
    3.                 form1.Controls.Add(t);

    Is there other way except form_load event cause it is not good to my application.

    thanks for the quick reply.


    Popskie

  5. #5
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,633

    Re: runtime control disappear when postback

    Well you could add the control at design time, but make it invisible, and then make it visible when u want. That would work.
    Alternatively, when you add it to the Controls collection, you could add a flag to the viewstate of the page to say that it's been added, then when your page reloads check this flag and add the control.

    Woof

  6. #6

    Thread Starter
    Fanatic Member popskie's Avatar
    Join Date
    Jul 2005
    Location
    In my chair
    Posts
    666

    Re: runtime control disappear when postback

    Ok Ill just find another process of my page. And thanks for the info and I think I have so many question in the future and hope u can entertain me.


    thanks and good day,

    Popskie

  7. #7
    Hyperactive Member kayos's Avatar
    Join Date
    Apr 2004
    Location
    Largo, Florida
    Posts
    306

    Re: [RESOLVED] runtime control disappear when postback

    In your Page_Load event you can use that same code but put an if statement in there to find out if the page is in postback like so:
    If Not Page.IsPostBack The
    'Code here
    Else

    End If


    If this post helps, please RATE MY POST!

    Using Visual Studio 2005 SE

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width