custom controls and datagrid

Discussion in 'ASP .Net' started by =?Utf-8?B?QmVu?=, Jun 3, 2004.

  1. Hi

    I've got a problem with a custon control that inherits form the UserControl class and that used the overlib javascript library. The control works well in a standard form but when I used it in a datagrid, the properties that were binded from the database doesn't keep their value through the page_load of the custom control. By using breakpoints on the properties methods of the control, I saw that they were all correctly binded and that the information coming from the database was correct. But when the page_load of the control was handled, the values coming from the db were all set to an empty string. All the controls in the datagrid works fine, but there is some missing informations in the display

    What could cause such a behavior? Is there a postback between the binding and the page_load of the controls? Why it is only the values coming from the db that disappears, and why the other controls binded from the db in the datagrid are correct?

    Thanks a lot for your time

    Bill
     
    =?Utf-8?B?QmVu?=, Jun 3, 2004
    #1
    1. Advertising

  2. "Ben" <> wrote in message
    news:...
    > Hi,
    >
    > I've got a problem with a custon control that inherits form the

    UserControl class and that used the overlib javascript library. The control
    works well in a standard form but when I used it in a datagrid, the
    properties that were binded from the database doesn't keep their value
    through the page_load of the custom control. By using breakpoints on the
    properties methods of the control, I saw that they were all correctly binded
    and that the information coming from the database was correct. But when the
    page_load of the control was handled, the values coming from the db were all
    set to an empty string. All the controls in the datagrid works fine, but
    there is some missing informations in the display.
    >
    > What could cause such a behavior? Is there a postback between the binding

    and the page_load of the controls? Why it is only the values coming from
    the db that disappears, and why the other controls binded from the db in the
    datagrid are correct?

    I would need more information in order to help you, or else you need less
    information in your question.

    Try simplifying the scenario first. For instance, try to reproduce the
    problem using a Repeater control instead of a DataGrid. Also, try a label
    inside of a Panel control. I have a suspicion that your problem may be
    related to the way that child control ids are changes inside of a container
    control.

    Also, see if the problem goes away if you're not using JavaScript, and try
    to reduce the problem to a single database field.
    --
    John Saunders
    johnwsaundersiii at hotmail
     
    John Saunders, Jun 3, 2004
    #2
    1. Advertising

  3. Thanks for the repl

    I tried the control in a repeater with a single field, and it still doesn't work. The database value is correctly sent to the control but the attribute doesn't keep his value when the page_load is called. I put a breakpoint in the set property of the attribute and the correct value from the database was there, then I put a breakpoint in the page_load where the attribute is used and it has become an empty string. Note that all of the other attributes still correct. I drop all the javascript used in my form but I cannot do the same with the javascript created by my control, because it is the main function of the control, to facilitate the use of the overlib javascript function. I assume that my script is fine because the control work well in any other case.

    That's about it, here's some sample of the code used, maybe it'll hel

    Thanks for your tim

    Here's how I declare the control in the repeate
    <asp:repeater id="Rep1" runat"server"><ItemTemplate><UserControl:MyUserControl id="RO" URLText="info" TitleBox="Details" TextBoxMouseOver='<%# DataBinder.Eval(Container.DataItem, "EmployeName") %>' runat="server"></UserControl:MyUserControl></ItemTemplate></asp:repeater >

    Here is how I bind the repeate

    Dim sql As String = "select Employe.Name As EmployeName FROM Employe WHERE Employe.GroupId = " & DDLGroup.SelectedValu

    Dim cmd As New SQLCommand(sql, Con.cn
    Con.cn.ope
    Me.Rep1.DataSource = cmd.ExecuteReade
    Me.Rep1.DataBind(
    Con.cn.close

    Hope someone can help me :
     
    =?Utf-8?B?QmVu?=, Jun 3, 2004
    #3
  4. "Ben" <> wrote in message
    news:...
    > Thanks for the reply
    >
    > I tried the control in a repeater with a single field, and it still

    doesn't work. The database value is correctly sent to the control but the
    attribute doesn't keep his value when the page_load is called. I put a
    breakpoint in the set property of the attribute and the correct value from
    the database was there, then I put a breakpoint in the page_load where the
    attribute is used and it has become an empty string. Note that all of the
    other attributes still correct. I drop all the javascript used in my form
    but I cannot do the same with the javascript created by my control, because
    it is the main function of the control, to facilitate the use of the overlib
    javascript function. I assume that my script is fine because the control
    work well in any other case.
    >
    > That's about it, here's some sample of the code used, maybe it'll help
    >
    > Thanks for your time
    >
    > Here's how I declare the control in the repeater
    > <asp:repeater id="Rep1"

    runat"server"><ItemTemplate><UserControl:MyUserControl id="RO"
    URLText="info" TitleBox="Details" TextBoxMouseOver='<%#
    DataBinder.Eval(Container.DataItem, "EmployeName") %>'
    runat="server"></UserControl:MyUserControl></ItemTemplate></asp:repeater >

    Does the same thing happen if you use an asp:Label instead of your user
    control?
    --
    John Saunders
    johnwsaundersiii at hotmail
     
    John Saunders, Jun 3, 2004
    #4
  5. "Ben" <> wrote in message
    news:...
    > ----- John Saunders wrote: -----
    >
    > "Ben" <> wrote in message
    > news:...
    > > Thanks for the reply
    > >> I tried the control in a repeater with a single field, and it

    still
    > doesn't work. The database value is correctly sent to the control

    but the
    > attribute doesn't keep his value when the page_load is called. I

    put a
    > breakpoint in the set property of the attribute and the correct value

    from
    > the database was there, then I put a breakpoint in the page_load

    where the
    > attribute is used and it has become an empty string. Note that all

    of the
    > other attributes still correct. I drop all the javascript used in

    my form
    > but I cannot do the same with the javascript created by my control,

    because
    > it is the main function of the control, to facilitate the use of the

    overlib
    > javascript function. I assume that my script is fine because the

    control
    > work well in any other case.
    > >> That's about it, here's some sample of the code used, maybe it'll

    help
    > >> Thanks for your time
    > >> Here's how I declare the control in the repeater

    > ><asp:repeater id="Rep1"

    > runat"server"><ItemTemplate><UserControl:MyUserControl id="RO"
    > URLText="info" TitleBox="Details" TextBoxMouseOver='<%#
    > DataBinder.Eval(Container.DataItem, "EmployeName") %>'
    >

    runat="server"></UserControl:MyUserControl></ItemTemplate></asp:repeater >
    >
    > Does the same thing happen if you use an asp:Label instead of your

    user
    > control?
    > --
    > John Saunders
    > johnwsaundersiii at hotmail
    >
    >
    > No, all the other web controls works fine; Even in my datagrid, all the

    other web controls in the rows were fine

    If all other controls, for instance Label or TextBox controls work, then the
    problem has nothing to do with the databinding expressions. Instead, it has
    to do with how your control deals with its property settings.

    You should review the Control Execution Lifecycle
    (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/ht
    ml/cpconcontrolexecutionlifecycle.asp?frame=true). Briefly, in the INIT
    phase, the control is instantiated and any properties with constant values
    are set to those values. By the LOAD phase, all controls are meant to be
    part of their parent's Controls collection. In the DataBind phase,
    properties with a databinding expression are set.

    For each databinding expression you have in the HTML source, ASP.NET creates
    an event handler for the control's DataBind event. That handler sets the
    properties to the specified values.

    Later, in the RENDER phase, the control is asked to render itself, using the
    property values.

    You may want to turn on page tracing. Additionally, I've found it extremely
    useful to override all the interesting methods on my controls and add
    Page.Trace calls to them. This way, I can see what's going in in great
    detail. I have gone as far as to create a base class for my controls and to
    put these trace calls in the base class.

    I suspect you'll find that the databinding is working, but that something
    then resets the property to the wrong value. At any rate, it may be time for
    an instrumentation run!
    --
    John Saunders
    johnwsaundersiii at hotmail
     
    John Saunders, Jun 3, 2004
    #5
  6. Thanks a lot for your help John

    Just discover the wonders of tracing and I found out that the page_load was raised before the database attribute binding, so i changed the page_load for a pre-render method in my control and all is great now!!! I'm very happy, it's been a long time since a tried to find an issue with this problem..

    Thanks a lot once again for your support!!! : )

    Ben
     
    =?Utf-8?B?QmVu?=, Jun 3, 2004
    #6
  7. The model often used is:

    private void Page_Load(object sender, EventArgs e)
    {
    if (!Page.IsPostBack)
    {
    // Load all of your data and then:
    Page.DataBind();
    }
    }

    --
    John Saunders
    johnwsaundersiii at hotmail

    "Ben" <> wrote in message
    news:...
    > Thanks a lot for your help John!
    >
    > Just discover the wonders of tracing and I found out that the page_load

    was raised before the database attribute binding, so i changed the page_load
    for a pre-render method in my control and all is great now!!! I'm very
    happy, it's been a long time since a tried to find an issue with this
    problem...
    >
    > Thanks a lot once again for your support!!! : )
    >
    > Ben
     
    John Saunders, Jun 3, 2004
    #7
    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. Axel Dahmen
    Replies:
    1
    Views:
    518
    Teemu Keiski
    Nov 12, 2003
  2. Dag
    Replies:
    5
    Views:
    476
    David Jessee
    May 8, 2004
  3. user
    Replies:
    1
    Views:
    441
    Kevin Spencer
    Jul 19, 2007
  4. rodchar
    Replies:
    0
    Views:
    399
    rodchar
    Nov 26, 2007
  5. Replies:
    3
    Views:
    376
    Angel
    Feb 6, 2008
Loading...

Share This Page