Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > custom controls and datagrid

Reply
Thread Tools

custom controls and datagrid

 
 
=?Utf-8?B?QmVu?=
Guest
Posts: n/a
 
      06-03-2004
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



 
Reply With Quote
 
 
 
 
John Saunders
Guest
Posts: n/a
 
      06-03-2004
"Ben" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?QmVu?=
Guest
Posts: n/a
 
      06-03-2004
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:MyUserCon trol 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 :


 
Reply With Quote
 
John Saunders
Guest
Posts: n/a
 
      06-03-2004
"Ben" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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:MyUserCon trol 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


 
Reply With Quote
 
John Saunders
Guest
Posts: n/a
 
      06-03-2004
"Ben" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> ----- John Saunders wrote: -----
>
> "Ben" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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:MyUserCon trol 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/de...-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


 
Reply With Quote
 
=?Utf-8?B?QmVu?=
Guest
Posts: n/a
 
      06-03-2004
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
 
Reply With Quote
 
John Saunders
Guest
Posts: n/a
 
      06-03-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
databound custom controls vs composite databound custom controls rodchar ASP .Net 0 11-26-2007 03:51 PM
Custom Controls: Import a custom namespace and use its functions within user ASP .Net 1 07-19-2007 11:03 AM
communication between an application, custom controls, and user controls Beatniks ASP .Net Building Controls 2 12-17-2005 10:11 PM
User Controls and Custom Controls Dag ASP .Net 5 05-08-2004 07:24 AM
IntelliSense on Web User Controls and Web Custom Controls Axel Dahmen ASP .Net 1 11-12-2003 06:12 AM



Advertisments