I read up on the page lifecycle but am still not getting this to work
correctly.

I have it in the Page_Init method:
if (this.IsPostBack){
    Control cont = new Control();
    cont = this.form1.FindControl("CATALOG_ID");
    string catId = ((HiddenField)cont).Value;
    HiddenField hf = new HiddenField();
    hf.ID = "CATALOG_ID";
    hf.Value = catId;
    hf.EnableViewState = true;
    Page.Controls.Add(hf);
}

and then cont = this.form1.FindControl("CATALOG_ID"); returns null
even though it is in the page that is being posted.  Is this the
incorrect command to get the input hidden field?


On Sep 10, 2:46 am, Cerebrus <[EMAIL PROTECTED]> wrote:
> Common newbie question, Adailey! The problem can be solved by re-
> adding the controls to the Page's control collection upon postback. I
> suggest reading up on the Page lifecycle in ASP.NET for a better
> understanding of what's going on behind the scenes.
>
> On Sep 10, 1:28 am, adailey <[EMAIL PROTECTED]> wrote:
>
> > I am adding some HiddenFields in the code behind Page_Init method that
> > is getting added to the form via form.Controls.Add(hiddenfield);  This
> > works fine.  When I view the source code of what is rendered in the
> > browser, it shows up as expected in the source view of the page.
>
> > However, my issue comes when I try to get at those hidden fields after
> > a submit is sent.  I would think that in the Page_Init method I would
> > be able to get at those hidden fields Control cont =
> > this.FindControl("ID") but they are not even there.  The only Controls
> > that are there are the ones that were created in the aspx page with
> > the <asp:> tags.
>
> > Sorry, this is probably an easy question.  Long time Java developer,
> > new to asp.net and C#.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web 
Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://cm.megasolutions.net/forums/default.aspx
-~----------~----~----~----~------~----~------~--~---

Reply via email to