Mantain Property

Discussion in 'ASP .Net Web Controls' started by Mike, Mar 14, 2005.

  1. Mike

    Mike Guest

    Hi,
    I don't know how to mantain the value of a Property of my WebCustomControl.
    I've my Control and set:
    ------Code in Page container of contrl ----...
    ....
    if(!IsPostBack)
    myControl.DataSource = myDataSource;
    myControl.DataTextField = "TextField";
    myControl.DataValueField = "ValueField";
    .....

    ------ Code in Contrl -----
    .....
    public string DataTextField
    {
    get{return this._dataTextField;}
    set{_dataTextField = value;}
    }
    ....

    and when PostBack raised the value of this propertys are null :(
    I can mantain the value using Session, but is little elegante.

    Someone has an example about this?

    THANKS!
     
    Mike, Mar 14, 2005
    #1
    1. Advertising

  2. Mike

    Brock Allen Guest

    To maintain data in a custom control across postbacks, don't store the data
    in a field. Instead store it in ViewState.

    public string DataTextField
    {
    get{
    if (ViewState["DataTextField"] == null) return "";
    return ViewState["DataTextField"] as string;
    }
    set{
    ViewState["DataTextField"] = value;
    }
    }

    -Brock
    http://staff.develop.com/ballen


    > Hi,
    > I don't know how to mantain the value of a Property of my
    > WebCustomControl.
    > I've my Control and set:
    > ------Code in Page container of contrl ----...
    > ...
    > if(!IsPostBack)
    > myControl.DataSource = myDataSource;
    > myControl.DataTextField = "TextField";
    > myControl.DataValueField = "ValueField";
    > ....
    > ------ Code in Contrl -----
    > ....
    > public string DataTextField
    > {
    > get{return this._dataTextField;}
    > set{_dataTextField = value;}
    > }
    > ...
    >
    > and when PostBack raised the value of this propertys are null :( I can
    > mantain the value using Session, but is little elegante.
    >
    > Someone has an example about this?
    >
    > THANKS!
    >
     
    Brock Allen, Mar 14, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jonathan

    Mantain ViewState

    Jonathan, Mar 9, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    436
    =?Utf-8?B?VmlzYXIgR2FzaGk=?=
    Mar 9, 2005
  2. billie
    Replies:
    3
    Views:
    313
    Sybren Stuvel
    Oct 5, 2005
  3. Mike

    Mantain Property

    Mike, Mar 14, 2005, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    120
  4. Jonathan

    Mantain ViewState

    Jonathan, Mar 10, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    113
    Jonathan
    Mar 10, 2005
  5. Alessandro Benedetti

    How to mantain the state between 2 call of the same WebService?

    Alessandro Benedetti, Mar 17, 2005, in forum: ASP .Net Web Services
    Replies:
    13
    Views:
    246
    Brock Allen
    Mar 17, 2005
Loading...

Share This Page