Connecting Tech Pros Worldwide Help | Site Map

control not found on postback

Igor Belagorudsky
Guest
 
Posts: n/a
#1: Nov 17 '05
Hi,

i am trying to analyze 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
 
Posts: n/a
#2: Nov 17 '05

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" <iggy1@hotmail.com> wrote in message
news:#xMbmOWVDHA.2364@TK2MSFTNGP09.phx.gbl...[color=blue]
> Hi,
>
> i am trying to analyze data submitted in a form but the problem is that[/color]
when[color=blue]
> i try to create the controls in code (which is what i want to do), it[/color]
throws[color=blue]
> 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)
> {
>
>[/color]
Debug.WriteLine(((WebControl)Page.FindControl("tes tBox_1")).Attributes["hell[color=blue]
> 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[/color]
it[color=blue]
> a hello=hi attribute, everything works like it should.
> can someone please tell me what the problem is?
>
> thanks,
> igor
>
>[/color]


Igor Belagorudsky
Guest
 
Posts: n/a
#3: Nov 17 '05

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_brubar@safeco.com> wrote in message
news:O0NE%23aWVDHA.1984@TK2MSFTNGP11.phx.gbl...[color=blue]
> you have to create the dynamic control on postback also. also for it to[/color]
have[color=blue]
> access to its postback data, you should create it during onint, as form[/color]
load[color=blue]
> is too late, the datapostback event has already fired.
>
> -- bruce (sqlwork.com)
>
>
> "Igor Belagorudsky" <iggy1@hotmail.com> wrote in message
> news:#xMbmOWVDHA.2364@TK2MSFTNGP09.phx.gbl...[color=green]
> > Hi,
> >
> > i am trying to analyze data submitted in a form but the problem is that[/color]
> when[color=green]
> > i try to create the controls in code (which is what i want to do), it[/color]
> throws[color=green]
> > 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)
> > {
> >
> >[/color]
>[/color]
Debug.WriteLine(((WebControl)Page.FindControl("tes tBox_1")).Attributes["hell[color=blue][color=green]
> > 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[/color][/color]
to[color=blue][color=green]
> > do is to debug.writeline "hi" on postback.
> > on the other hand, if i manually put a text box in the aspx page and[/color][/color]
give[color=blue]
> it[color=green]
> > a hello=hi attribute, everything works like it should.
> > can someone please tell me what the problem is?
> >
> > thanks,
> > igor
> >
> >[/color]
>
>[/color]


MS News
Guest
 
Posts: n/a
#4: Nov 17 '05

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" <iggy1@hotmail.com> wrote in message
news:#QVZz9WVDHA.624@TK2MSFTNGP10.phx.gbl...[color=blue]
> 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_brubar@safeco.com> wrote in message
> news:O0NE%23aWVDHA.1984@TK2MSFTNGP11.phx.gbl...[color=green]
> > you have to create the dynamic control on postback also. also for it to[/color]
> have[color=green]
> > access to its postback data, you should create it during onint, as form[/color]
> load[color=green]
> > is too late, the datapostback event has already fired.
> >
> > -- bruce (sqlwork.com)
> >
> >
> > "Igor Belagorudsky" <iggy1@hotmail.com> wrote in message
> > news:#xMbmOWVDHA.2364@TK2MSFTNGP09.phx.gbl...[color=darkred]
> > > Hi,
> > >
> > > i am trying to analyze data submitted in a form but the problem is[/color][/color][/color]
that[color=blue][color=green]
> > when[color=darkred]
> > > i try to create the controls in code (which is what i want to do), it[/color]
> > throws[color=darkred]
> > > an obect not found exception on postback when i try to[/color][/color][/color]
Page.FindControl:[color=blue][color=green][color=darkred]
> > >
> > > private void Page_Load(object sender, System.EventArgs e)
> > > {
> > > if (Page.IsPostBack)
> > > {
> > >
> > >[/color]
> >[/color]
>[/color]
Debug.WriteLine(((WebControl)Page.FindControl("tes tBox_1")).Attributes["hell[color=blue][color=green][color=darkred]
> > > 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[/color][/color][/color]
trying[color=blue]
> to[color=green][color=darkred]
> > > do is to debug.writeline "hi" on postback.
> > > on the other hand, if i manually put a text box in the aspx page and[/color][/color]
> give[color=green]
> > it[color=darkred]
> > > a hello=hi attribute, everything works like it should.
> > > can someone please tell me what the problem is?
> > >
> > > thanks,
> > > igor
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Closed Thread