Professional Web Applications Themes

control not found on postback - ASP.NET General

Hi, i am trying to yze data submitted in a form but the problem is that when i try to create the controls in code (which is what i want to do), it throws an obect not found exception on postback when i try to Page.FindControl: private void Page_Load(object sender, System.EventArgs e) { if (Page.IsPostBack) { Debug.WriteLine(((WebControl)Page.FindControl("tes tBox_1")).Attributes["hell o"]); } else { TextBox txt = new TextBox(); txt.ID = "testBox_1"; txt.Attributes.Add("hello", "hi"); Page.FindControl("test").Controls.Add(txt); } } where control "test" is the form that i am submitting and all im trying to do is to debug.writeline "hi" on postback. on the other ...

  1. #1

    Default control not found on postback

    Hi,

    i am trying to yze data submitted in a form but the problem is that when
    i try to create the controls in code (which is what i want to do), it throws
    an obect not found exception on postback when i try to Page.FindControl:

    private void Page_Load(object sender, System.EventArgs e)
    {
    if (Page.IsPostBack)
    {

    Debug.WriteLine(((WebControl)Page.FindControl("tes tBox_1")).Attributes["hell
    o"]);
    }
    else
    {
    TextBox txt = new TextBox();
    txt.ID = "testBox_1";
    txt.Attributes.Add("hello", "hi");
    Page.FindControl("test").Controls.Add(txt);
    }
    }

    where control "test" is the form that i am submitting and all im trying to
    do is to debug.writeline "hi" on postback.
    on the other hand, if i manually put a text box in the aspx page and give it
    a hello=hi attribute, everything works like it should.
    can someone please tell me what the problem is?

    thanks,
    igor


    Igor Belagorudsky Guest

  2. #2

    Default Re: control not found on postback

    you have to create the dynamic control on postback also. also for it to have
    access to its postback data, you should create it during onint, as form load
    is too late, the datapostback event has already fired.

    -- bruce (sqlwork.com)


    "Igor Belagorudsky" <iggy1hotmail.com> wrote in message
    news:#xMbmOWVDHA.2364TK2MSFTNGP09.phx.gbl...
    > Hi,
    >
    > i am trying to yze data submitted in a form but the problem is that
    when
    > i try to create the controls in code (which is what i want to do), it
    throws
    > an obect not found exception on postback when i try to Page.FindControl:
    >
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > if (Page.IsPostBack)
    > {
    >
    >
    Debug.WriteLine(((WebControl)Page.FindControl("tes tBox_1")).Attributes["hell
    > o"]);
    > }
    > else
    > {
    > TextBox txt = new TextBox();
    > txt.ID = "testBox_1";
    > txt.Attributes.Add("hello", "hi");
    > Page.FindControl("test").Controls.Add(txt);
    > }
    > }
    >
    > where control "test" is the form that i am submitting and all im trying to
    > do is to debug.writeline "hi" on postback.
    > on the other hand, if i manually put a text box in the aspx page and give
    it
    > a hello=hi attribute, everything works like it should.
    > can someone please tell me what the problem is?
    >
    > thanks,
    > igor
    >
    >

    bruce barker Guest

  3. #3

    Default Re: control not found on postback

    hi,

    thanks for your response, but i have a more complicated structure
    unfortunately...

    i dont need to display the same page on postback. i have a sort of
    questionnaire setup where my page checks what questions to ask in the db,
    creates appropriate form elements and waits for submission. then it writes
    down answers and displays the next questions in the same page. so i really
    need the data from my dynamic control without having to recreate it on the
    page.. is this possible and if so at which point would i be able to check
    its data? oninit?

    thank you,
    igor

    "bruce barker" <nospam_brubarsafeco.com> wrote in message
    news:O0NE%23aWVDHA.1984TK2MSFTNGP11.phx.gbl...
    > you have to create the dynamic control on postback also. also for it to
    have
    > access to its postback data, you should create it during onint, as form
    load
    > is too late, the datapostback event has already fired.
    >
    > -- bruce (sqlwork.com)
    >
    >
    > "Igor Belagorudsky" <iggy1hotmail.com> wrote in message
    > news:#xMbmOWVDHA.2364TK2MSFTNGP09.phx.gbl...
    > > Hi,
    > >
    > > i am trying to yze data submitted in a form but the problem is that
    > when
    > > i try to create the controls in code (which is what i want to do), it
    > throws
    > > an obect not found exception on postback when i try to Page.FindControl:
    > >
    > > private void Page_Load(object sender, System.EventArgs e)
    > > {
    > > if (Page.IsPostBack)
    > > {
    > >
    > >
    >
    Debug.WriteLine(((WebControl)Page.FindControl("tes tBox_1")).Attributes["hell
    > > o"]);
    > > }
    > > else
    > > {
    > > TextBox txt = new TextBox();
    > > txt.ID = "testBox_1";
    > > txt.Attributes.Add("hello", "hi");
    > > Page.FindControl("test").Controls.Add(txt);
    > > }
    > > }
    > >
    > > where control "test" is the form that i am submitting and all im trying
    to
    > > do is to debug.writeline "hi" on postback.
    > > on the other hand, if i manually put a text box in the aspx page and
    give
    > it
    > > a hello=hi attribute, everything works like it should.
    > > can someone please tell me what the problem is?
    > >
    > > thanks,
    > > igor
    > >
    > >
    >
    >

    Igor Belagorudsky Guest

  4. #4

    Default Re: control not found on postback

    Igor,

    I am having the same problem here.
    I am going to Try this:
    on Page postback recreate the same dynamic controls first
    Process the results
    then create the new questions
    response

    I know this is inefficient but what else to do other than some java script??

    Let us know if this works


    "Igor Belagorudsky" <iggy1hotmail.com> wrote in message
    news:#QVZz9WVDHA.624TK2MSFTNGP10.phx.gbl...
    > hi,
    >
    > thanks for your response, but i have a more complicated structure
    > unfortunately...
    >
    > i dont need to display the same page on postback. i have a sort of
    > questionnaire setup where my page checks what questions to ask in the db,
    > creates appropriate form elements and waits for submission. then it writes
    > down answers and displays the next questions in the same page. so i really
    > need the data from my dynamic control without having to recreate it on the
    > page.. is this possible and if so at which point would i be able to check
    > its data? oninit?
    >
    > thank you,
    > igor
    >
    > "bruce barker" <nospam_brubarsafeco.com> wrote in message
    > news:O0NE%23aWVDHA.1984TK2MSFTNGP11.phx.gbl...
    > > you have to create the dynamic control on postback also. also for it to
    > have
    > > access to its postback data, you should create it during onint, as form
    > load
    > > is too late, the datapostback event has already fired.
    > >
    > > -- bruce (sqlwork.com)
    > >
    > >
    > > "Igor Belagorudsky" <iggy1hotmail.com> wrote in message
    > > news:#xMbmOWVDHA.2364TK2MSFTNGP09.phx.gbl...
    > > > Hi,
    > > >
    > > > i am trying to yze data submitted in a form but the problem is
    that
    > > when
    > > > i try to create the controls in code (which is what i want to do), it
    > > throws
    > > > an obect not found exception on postback when i try to
    Page.FindControl:
    > > >
    > > > private void Page_Load(object sender, System.EventArgs e)
    > > > {
    > > > if (Page.IsPostBack)
    > > > {
    > > >
    > > >
    > >
    >
    Debug.WriteLine(((WebControl)Page.FindControl("tes tBox_1")).Attributes["hell
    > > > o"]);
    > > > }
    > > > else
    > > > {
    > > > TextBox txt = new TextBox();
    > > > txt.ID = "testBox_1";
    > > > txt.Attributes.Add("hello", "hi");
    > > > Page.FindControl("test").Controls.Add(txt);
    > > > }
    > > > }
    > > >
    > > > where control "test" is the form that i am submitting and all im
    trying
    > to
    > > > do is to debug.writeline "hi" on postback.
    > > > on the other hand, if i manually put a text box in the aspx page and
    > give
    > > it
    > > > a hello=hi attribute, everything works like it should.
    > > > can someone please tell me what the problem is?
    > > >
    > > > thanks,
    > > > igor
    > > >
    > > >
    > >
    > >
    >
    >

    MS News Guest

Similar Threads

  1. control id and name for postback mechanism
    By Martin in forum ASP.NET Building Controls
    Replies: 1
    Last Post: August 20th, 08:55 AM
  2. How do I do a postback to a user control?
    By Arne in forum ASP.NET Building Controls
    Replies: 3
    Last Post: September 22nd, 03:28 PM
  3. Did my control caused the postback
    By Teemu Keiski in forum ASP.NET Building Controls
    Replies: 6
    Last Post: September 4th, 10:06 PM
  4. What Control Caused the PostBack?
    By Jeff Voigt in forum ASP.NET General
    Replies: 2
    Last Post: August 8th, 06:09 PM
  5. Which control had focus before postback?
    By Marco Liedekerken in forum ASP.NET General
    Replies: 2
    Last Post: July 1st, 04:43 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139