473,378 Members | 1,471 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

custom controls and datagrid

Ben
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

Nov 18 '05 #1
6 1456
"Ben" <bi***********@hotmail.com> wrote in message
news:13**********************************@microsof t.com...
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
Nov 18 '05 #2
Ben
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 :
Nov 18 '05 #3
"Ben" <an*******@discussions.microsoft.com> wrote in message
news:4B**********************************@microsof t.com...
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
Nov 18 '05 #4
"Ben" <an*******@discussions.microsoft.com> wrote in message
news:5D**********************************@microsof t.com...
----- John Saunders wrote: -----

"Ben" <an*******@discussions.microsoft.com> wrote in message
news:4B**********************************@microsof t.com...
> 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
Nov 18 '05 #5
Ben
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
Nov 18 '05 #6
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" <an*******@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.com...
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

Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mark | last post by:
I need some advice on how to acheive the desired result of my custom page link generation. The datagrid 'built-in' page navigation only allows either the 'Prev/Next' or the page numbers. ...
2
by: SammyBar | last post by:
Hi, I'm trying to bind a custom collection class to a data grid, following the guidelines from the article http://msdn.microsoft.com/msdnmag/issues/05/08/CollectionsandDataBinding/default.aspx....
0
by: Lenny | last post by:
Hello, I have an html table template which I want to turn into ASP.NET custom control. I want to utilize the best features of OOP. I want to be able to create columns headings dynamically, add...
2
by: Jay Walker | last post by:
I created a custom DataGridColumn based on Marcie Robillard's MSDN Article: Creating Custom Columns for the ASP.NET Datagrid...
4
by: The Alchemist | last post by:
I am having a problem with a dynamically-generated Datagrid. It is important to point out that this problem does not exist with a design-time created Datagrid, but only with a dynamically generated...
7
by: Girish | last post by:
OK.. phew. Playing with data grids for the past few days has been fun and a huge learning experience.. My problem. I have a requirement to display a gird with a gird. Within the embedded grid,...
1
by: nate axtell | last post by:
In VB .Net I made a custom CheckBox column style (for the Datagrid control) that maps to two DataTable columns , one it uses for the Checked status and the other it uses for the Enabled status. I am...
1
by: rn5a | last post by:
I have created a custom server control which is actually a Button clicking which prompts a user with a JavaScript confirm message asking him whether he would like to proceed or not. If he clicks...
3
by: Cyr1dian | last post by:
Hi, My problem is that a custom control "newA" that inherits from a base custom control "baseA" is not displaying any contained controls - that were not inherited - at run time, but displays...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.