Results 1 to 3 of 3

Thread: [RESOLVED] Seems unable to set value of hidden control

  1. #1

    Thread Starter
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    Resolved [RESOLVED] Seems unable to set value of hidden control

    Note: Going to be posting a few silly questions (seems to be silly problems) so be warned, my webforms knowledge are pretty low.

    I got a hidden control in a User Control, as follows:
    Code:
    <asp:HiddenField ID="workDateId" runat="server" Value="" />
    The user control have a member:
    Code:
    public string WorkDateId { get; set; }
    In the form load event for the user control I set the value of my hidden control to the value of my member:
    Code:
    workDateId.Value = WorkDateId;
    I use the user control as follows:
    Code:
    var ctrl = (TestControl)LoadControl("TestControl.ascx");
    ctrl.WorkDateId = "some nonsense";
    var cell = new TableCell();
    cell.Controls.Add(ctrl);
    tblRow.Cells.Add(cell);
    However, the value of the hidden control are never set.

    So..what did I miss?


  2. #2

    Thread Starter
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    Re: Seems unable to set value of hidden control

    Solved it. (guess I forgot the page lifecycle stuff)

    Changed my auto property to set the control value as soon it's value changes.
    Code:
            private string _workDateId;
    
            public string WorkDateId
            {
                get { return _workDateId; }
                set
                {
                    _workDateId = value;
                    workDateId.Value = _workDateId;
                }
            }
    Okey Dokey now. (and posting next stupid one soon ;-) )


  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Seems unable to set value of hidden control

    Quote Originally Posted by Krokonoster View Post
    guess I forgot the page lifecycle stuff
    This is always something that comes back to bite you every so often

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