PlaceHolder Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Oren

    PlaceHolder Question

    hi,
    How can I retrieve the Control (wucState.ascx) from the Placeholder at the
    even: btn_Click:
    //declaration at page
    protected wucState WucState1; -- my control
    ....
    private void Page_Load(objec t sender, System.EventArg s e)
    {
    ....
    WucState1 = Page.LoadContro l("wucState.asc x") as wucState;
    plhState.Contro ls.Add(WucState 1);
    ....
    }
    ....
    private void btn_Click(objec t sender, System.EventArg s e)
    {
    WucState1 = (wucState)plhSt ate.Controls[0]; // ERROR !!!!!! CANNOT FIND
    THE CONTROL
    ....
    }

    any idea ? please with code sample.

    thanx,
    Oren

  • Karl Seguin

    #2
    Re: PlaceHolder Question

    It isn't clear from your code whether or not you are adding the control to
    your placeholder during postback. Ie, if you have the Page.LoadContro l and
    plhState.Contro ls.Add lines below in a if (!Page.IsPostBa ck) then things
    won't work.

    Also, since you've scoped WucState1 as a field (seems like it should be
    private, not public, but that doesn't mater), why not just use WucState1 in
    yoru click?

    public class Index: Page
    {
    private wucState _wucState1;
    private void Page_Load(objec t sender, System.EventArg s e)
    {
    _wucState1 = (wucState)Page. LoadControl("wu cState.ascx");
    plhState.Contro ls.Add(_wucStat e1);
    if (!Page.IsPostBa ck)
    {
    //do stuff
    }
    }
    private void btn_Click(objec t sender, System.EventArg s e)
    {
    _wucState1.What ever //shouldn't be null, because it was recreated
    in page_load on postback
    }
    }

    Karl

    --
    MY ASP.Net tutorials
    Programming blog exploring Zig, Elixir, Go, Testing, Design and Performance

    http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!



    "Oren" <Oren@discussio ns.microsoft.co m> wrote in message
    news:7086B9B6-6FAE-4673-B8D7-42144ADEAC72@mi crosoft.com...[color=blue]
    > hi,
    > How can I retrieve the Control (wucState.ascx) from the Placeholder at the
    > even: btn_Click:
    > //declaration at page
    > protected wucState WucState1; -- my control
    > ...
    > private void Page_Load(objec t sender, System.EventArg s e)
    > {
    > ...
    > WucState1 = Page.LoadContro l("wucState.asc x") as wucState;
    > plhState.Contro ls.Add(WucState 1);
    > ...
    > }
    > ...
    > private void btn_Click(objec t sender, System.EventArg s e)
    > {
    > WucState1 = (wucState)plhSt ate.Controls[0]; // ERROR !!!!!! CANNOT FIND
    > THE CONTROL
    > ...
    > }
    >
    > any idea ? please with code sample.
    >
    > thanx,
    > Oren
    >[/color]


    Comment

    • Oren

      #3
      Re: PlaceHolder Question

      Karl,
      the "Page.Controls. Add" is inside "if (!Page.IsPostBa ck)". On the Click
      event I need to retreive some data that was changed in the control.

      public class Index: Page
      {
      private wucState _wucState1;
      private System.Web.UI.W ebControls.Plac eHolder plhOrder;
      private void Page_Load(objec t sender, System.EventArg s e)
      {
      if (!Page.IsPostBa ck)
      {
      _wucState1 = (wucState)Page. LoadControl("wu cState.ascx");
      plhState.Contro ls.Add(_wucStat e1);
      }
      }
      private void btn_Click(objec t sender, System.EventArg s e)
      {
      _wucState1 = (wucState)plhSt ate.Controls[0]; // ERROR
      }
      }


      "Karl Seguin" wrote:
      [color=blue]
      > It isn't clear from your code whether or not you are adding the control to
      > your placeholder during postback. Ie, if you have the Page.LoadContro l and
      > plhState.Contro ls.Add lines below in a if (!Page.IsPostBa ck) then things
      > won't work.
      >
      > Also, since you've scoped WucState1 as a field (seems like it should be
      > private, not public, but that doesn't mater), why not just use WucState1 in
      > yoru click?
      >
      > public class Index: Page
      > {
      > private wucState _wucState1;
      > private void Page_Load(objec t sender, System.EventArg s e)
      > {
      > _wucState1 = (wucState)Page. LoadControl("wu cState.ascx");
      > plhState.Contro ls.Add(_wucStat e1);
      > if (!Page.IsPostBa ck)
      > {
      > //do stuff
      > }
      > }
      > private void btn_Click(objec t sender, System.EventArg s e)
      > {
      > _wucState1.What ever //shouldn't be null, because it was recreated
      > in page_load on postback
      > }
      > }
      >
      > Karl
      >
      > --
      > MY ASP.Net tutorials
      > http://www.openmymind.net/
      > http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!
      >
      >
      >
      > "Oren" <Oren@discussio ns.microsoft.co m> wrote in message
      > news:7086B9B6-6FAE-4673-B8D7-42144ADEAC72@mi crosoft.com...[color=green]
      > > hi,
      > > How can I retrieve the Control (wucState.ascx) from the Placeholder at the
      > > even: btn_Click:
      > > //declaration at page
      > > protected wucState WucState1; -- my control
      > > ...
      > > private void Page_Load(objec t sender, System.EventArg s e)
      > > {
      > > ...
      > > WucState1 = Page.LoadContro l("wucState.asc x") as wucState;
      > > plhState.Contro ls.Add(WucState 1);
      > > ...
      > > }
      > > ...
      > > private void btn_Click(objec t sender, System.EventArg s e)
      > > {
      > > WucState1 = (wucState)plhSt ate.Controls[0]; // ERROR !!!!!! CANNOT FIND
      > > THE CONTROL
      > > ...
      > > }
      > >
      > > any idea ? please with code sample.
      > >
      > > thanx,
      > > Oren
      > >[/color]
      >
      >
      >[/color]

      Comment

      • Karl Seguin

        #4
        Re: PlaceHolder Question

        As i said (and my example showed), it must be OUTSIDE the
        !Page.IsPostbac k....you can't find the control because on postback, it was
        never recreated and added to the placeholder..

        Karl
        --
        MY ASP.Net tutorials
        Programming blog exploring Zig, Elixir, Go, Testing, Design and Performance

        http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!



        "Oren" <Oren@discussio ns.microsoft.co m> wrote in message
        news:7CD53AAB-7BAC-463F-B450-9D816D3FD753@mi crosoft.com...[color=blue]
        > Karl,
        > the "Page.Controls. Add" is inside "if (!Page.IsPostBa ck)". On the Click
        > event I need to retreive some data that was changed in the control.
        >
        > public class Index: Page
        > {
        > private wucState _wucState1;
        > private System.Web.UI.W ebControls.Plac eHolder plhOrder;
        > private void Page_Load(objec t sender, System.EventArg s e)
        > {
        > if (!Page.IsPostBa ck)
        > {
        > _wucState1 = (wucState)Page. LoadControl("wu cState.ascx");
        > plhState.Contro ls.Add(_wucStat e1);
        > }
        > }
        > private void btn_Click(objec t sender, System.EventArg s e)
        > {
        > _wucState1 = (wucState)plhSt ate.Controls[0]; // ERROR
        > }
        > }
        >
        >
        > "Karl Seguin" wrote:
        >[color=green]
        >> It isn't clear from your code whether or not you are adding the control
        >> to
        >> your placeholder during postback. Ie, if you have the Page.LoadContro l
        >> and
        >> plhState.Contro ls.Add lines below in a if (!Page.IsPostBa ck) then
        >> things
        >> won't work.
        >>
        >> Also, since you've scoped WucState1 as a field (seems like it should be
        >> private, not public, but that doesn't mater), why not just use WucState1
        >> in
        >> yoru click?
        >>
        >> public class Index: Page
        >> {
        >> private wucState _wucState1;
        >> private void Page_Load(objec t sender, System.EventArg s e)
        >> {
        >> _wucState1 = (wucState)Page. LoadControl("wu cState.ascx");
        >> plhState.Contro ls.Add(_wucStat e1);
        >> if (!Page.IsPostBa ck)
        >> {
        >> //do stuff
        >> }
        >> }
        >> private void btn_Click(objec t sender, System.EventArg s e)
        >> {
        >> _wucState1.What ever //shouldn't be null, because it was
        >> recreated
        >> in page_load on postback
        >> }
        >> }
        >>
        >> Karl
        >>
        >> --
        >> MY ASP.Net tutorials
        >> http://www.openmymind.net/
        >> http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!
        >>
        >>
        >>
        >> "Oren" <Oren@discussio ns.microsoft.co m> wrote in message
        >> news:7086B9B6-6FAE-4673-B8D7-42144ADEAC72@mi crosoft.com...[color=darkred]
        >> > hi,
        >> > How can I retrieve the Control (wucState.ascx) from the Placeholder at
        >> > the
        >> > even: btn_Click:
        >> > //declaration at page
        >> > protected wucState WucState1; -- my control
        >> > ...
        >> > private void Page_Load(objec t sender, System.EventArg s e)
        >> > {
        >> > ...
        >> > WucState1 = Page.LoadContro l("wucState.asc x") as wucState;
        >> > plhState.Contro ls.Add(WucState 1);
        >> > ...
        >> > }
        >> > ...
        >> > private void btn_Click(objec t sender, System.EventArg s e)
        >> > {
        >> > WucState1 = (wucState)plhSt ate.Controls[0]; // ERROR !!!!!! CANNOT
        >> > FIND
        >> > THE CONTROL
        >> > ...
        >> > }
        >> >
        >> > any idea ? please with code sample.
        >> >
        >> > thanx,
        >> > Oren
        >> >[/color]
        >>
        >>
        >>[/color][/color]


        Comment

        Working...