custom controls and datagrid

G

Guest

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
 
J

John Saunders

Ben said:
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.
 
G

Guest

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 :
 
J

John Saunders

Ben said:
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?
 
J

John Saunders

Ben said:
----- John Saunders wrote: -----

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.
runat"server"><ItemTemplate><UserControl:MyUserControl id="RO"
URLText="info" TitleBox="Details" TextBoxMouseOver='<%#
DataBinder.Eval(Container.DataItem, "EmployeName") %>'
runat="server"> said:
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!
 
G

Guest

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
 
J

John Saunders

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 said:
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...
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top