473,698 Members | 2,022 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1475
"Ben" <bi***********@ hotmail.com> wrote in message
news:13******** *************** ***********@mic rosoft.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
johnwsaundersii i 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><U serControl:MyUs erControl id="RO" URLText="info" TitleBox="Detai ls" TextBoxMouseOve r='<%# DataBinder.Eval (Container.Data Item, "EmployeNam e") %>' runat="server"> </UserControl:MyU serControl></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.Select edValu

Dim cmd As New SQLCommand(sql, Con.cn
Con.cn.ope
Me.Rep1.DataSou rce = cmd.ExecuteRead e
Me.Rep1.DataBin d(
Con.cn.close

Hope someone can help me :
Nov 18 '05 #3
"Ben" <an*******@disc ussions.microso ft.com> wrote in message
news:4B******** *************** ***********@mic rosoft.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><U serControl:MyUs erControl id="RO"
URLText="info" TitleBox="Detai ls" TextBoxMouseOve r='<%#
DataBinder.Eval (Container.Data Item, "EmployeNam e") %>'
runat="server"> </UserControl:MyU serControl></ItemTemplate></asp:repeater >

Does the same thing happen if you use an asp:Label instead of your user
control?
--
John Saunders
johnwsaundersii i at hotmail
Nov 18 '05 #4
"Ben" <an*******@disc ussions.microso ft.com> wrote in message
news:5D******** *************** ***********@mic rosoft.com...
----- John Saunders wrote: -----

"Ben" <an*******@disc ussions.microso ft.com> wrote in message
news:4B******** *************** ***********@mic rosoft.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:repeate r id="Rep1"

runat"server">< ItemTemplate><U serControl:MyUs erControl id="RO"
URLText="info" TitleBox="Detai ls" TextBoxMouseOve r='<%#
DataBinder.Eval (Container.Data Item, "EmployeNam e") %>'

runat="server"> </UserControl:MyU serControl></ItemTemplate></asp:repeater >
Does the same thing happen if you use an asp:Label instead of your user control?
--
John Saunders
johnwsaundersii i 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/cpconcontrolexe cutionlifecycle .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
johnwsaundersii i 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(objec t sender, EventArgs e)
{
if (!Page.IsPostBa ck)
{
// Load all of your data and then:
Page.DataBind() ;
}
}

--
John Saunders
johnwsaundersii i at hotmail

"Ben" <an*******@disc ussions.microso ft.com> wrote in message
news:C3******** *************** ***********@mic rosoft.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
1195
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. (Prev/Next on top and pg numbers on bottom is not an option) Therefore I am attempting to create my own custom navigation where I am very close except for the rendering of the page number links after clicking on one of them. In other words, Initial page...
2
2748
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. The problem is the article is in VisualBasic. I already get the collection to be recognized as a Data Source by the IDE. It populated the DataGrid correctly from the fields on the items object of the collection, but I can't get the DataGrid to...
0
1500
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 buttons to the footer of the table, etc. A datagrid control wont work for me, because I want to have custom buttons images for paging and sorting. Here is one thing I have the most difficulty with: I need a way to have a "master" custom table...
2
3193
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 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/creatingcustomcolumns.asp The problem I am having is that the data in the custom datagridcolumn is not saved to viewstate and after postback, the column does not contain data.
4
2121
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 Datagrid in a Web Custom Control (WCC) : The datagrid has LinkButton Column which has a select LinkButton for each row. When this button is clicked, the Datagrid raises its 'ItemCommand' event which captures the information for that row and...
7
3341
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, theres a requirement to show a drop down menu list (this is a control I downloaded online) in one of the columns. For the purposes of this question, Ive implemented the drop down menu as a drop down list instead. Ive got all this working at this...
1
3586
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 having a couple problems so far. 1. with the way the Paint method works: When I scroll to the right, the custom column gets Drawn on top of the left-most "Selecting" column (the one where the green arrows are displayed). How can I possibly modify...
1
1440
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 *OK' in the confirm box, he is taken to the next page. If he clicks *Cancel* in the confirm box, he stays on that page itself. I have a Web Form which houses a DataGrid. To edit the data in the DataGrid, I am using <asp:EditCommandColumn/>. To...
3
1314
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 them fine at design time. I'll give a short example: public class baseA: UserControl
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9027
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2329
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.