CodeVerge.Net Beta


   Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: Date Entered: 11/24/2003 1:16:41 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 6 Views: 41 Favorited: 0 Favorite
7 Items, 1 Pages 1 |< << Go >> >|
"cericoli" <>
NewsGroup User
User Control events11/24/2003 1:16:41 AM

0

Hi,

I am trying to create a reusable user control which is essentially a datagrid with certain formatting and features. I am trying to understand the usage of user controls, and am struggling with something.

Essentially i am trying to create three datagrids, each successively dependant on the selectedindex value of the previous grid. ie. i click on the first grid, and it fills the values of the second grid. click on the second grid and it drills down to the values for the third grid etc.

I am trying to use the same user control for each grid, but obviously need to access the selectedindexchanged event within the user control. to test, i load the control into a placeholder in the main page and bind the control. This works fine. However, when i click on the control to change the selected item, it does not trigger the event withing the user control. I have read briefly about 'bubbling' events, but this seems to refer to handling user control events in the main page, whereas i want to manage them within the control.

Can anyone help at all?

CHeers

Chris
"master4eva" <>
NewsGroup User
Re: User Control events11/24/2003 7:01:48 AM

0

You will have to ensure that your user controls and the three datagrids that you create dynamically have a static ID.

DataGrid1.ID = "DG1";

-- Justin Lovell
"cericoli" <>
NewsGroup User
Re: User Control events11/24/2003 10:00:18 AM

0

Hi

Thanks so much for taking the time to help...

I did as suggested and it has not helped. Essentially the problem appears to be that the event contained within the user control (selectedindexchanged) is not being triggered by the postback link that is created by the Select Command.

If i compare a datagrid that is not contained within a usercontrol, the link for the Select hyperlink is javascript:__doPostBack('DataGrid1$_ctl21$_ctl0','')

Where DataGrid1 is the ID i have given the datagrid, and ctl21 refers to the cell (or row) and ctl0 refers to the control that triggered the postback.

This compares to the link generated by the Select command in the user control datagrid:

javascript:__doPostBack('ctlDatagrid2$dgCategory$_ctl9$_ctl0','')

Where dgCategory is the ID of the datagrid WITHIN the user control, and ctlDatagrid2 is the ID of the user control within the main aspx page.

When clicking the select link within the user control's datagrid, the page definately posts back, but does NOT trigger the SelectedIndexChanged event within the usercontrol's datagrid, nor does it trigger the CommandEvent.

I am completely stuffed, and have no idea. If you can help, that would be fantastic!!!

Cheers

Chris



"master4eva" <>
NewsGroup User
Re: User Control events11/24/2003 11:13:20 AM

0

Yes, the DataGrid does bubble events. I am assuming that you are using the LinkControl (that is what it sounds like). The only code that I need posted here is DataGrid1 (the page declaration) and then I will be on my way to answer precisely.
-- Justin Lovell
"cericoli" <>
NewsGroup User
Re: User Control events11/24/2003 11:21:55 PM

0

Hi Justin,

I am not sure if you meant Datagrid1 when requesting code. I included that example as a contrast. Datagrid1 is the same datagrid, but not contained in a user control (and the postback works perfectly).

So I have posted the code for the dgCategory user control, and the instantiation of this control from from the main aspx page.

(Sorry - I changed some of the object names in previous posts to make it simpler, so hopefully the code is clear)

Thanks again for taking the time to look at this

Cheers

Chris



USER CONTROL



Public Class spec_datagrid
Inherits System.Web.UI.UserControl

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub
Protected WithEvents dg1Header As System.Web.UI.WebControls.Label
Protected WithEvents dgCategory As System.Web.UI.WebControls.DataGrid

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Public Property ViewType() As Integer
Get
ViewType = pViewType
End Get
Set(ByVal Value As Integer)
pViewType = ViewType
End Set
End Property
Public Property SelectedID() As Integer
Get
SelectedID = pSelectedID
End Get
Set(ByVal Value As Integer)
pSelectedID = Value
End Set
End Property
Public Property Tier() As Integer
Get
Tier = pTier
End Get
Set(ByVal Value As Integer)
pTier = Value
End Set
End Property
Public Property HasChild() As Boolean
Get
HasChild = pHasChild
End Get
Set(ByVal Value As Boolean)
pHasChild = Value
End Set
End Property
Public Property ParentID() As Integer
Get
ParentID = pParentID
End Get
Set(ByVal Value As Integer)
pParentID = Value
End Set
End Property

Private pViewType As Integer ' 0 = Group, 1 = Vendor
Private pSelectedID As Integer ' Obtained when selecteditemchanged event fires
Private pTier As Integer ' Indicates the current tier
Private pHasChild As Boolean ' Determines whether a downstream binding is required
Private pParentID As Integer ' Obtained from parent datagrid

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

If Page.IsPostBack = False Then

SelectedID = Nothing
Me.dgCategory.Columns(0).Visible = True
Me.dgCategory.Columns(2).Visible = False

End If

End Sub


Private Sub dgCategory_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgCategory.ItemDataBound

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then

e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#eeeeee'")
e.Item.Style("cursor") = "hand"
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='white'")

' Dim button As LinkButton = CType(e.Item.Cells(0).Controls(0), LinkButton)
' e.Item.Attributes("onclick") = Page.GetPostBackClientHyperlink(button, "")

End If

If e.Item.ItemType = ListItemType.SelectedItem Then

e.Item.Style("backgroundcolor") = "#A3C2F0"
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#A3C2F0'")

End If

End Sub

Public Sub dgCategory_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgCategory.SelectedIndexChanged

Dim dg As DataGrid = CType(sender, DataGrid)
Dim drws As DataGridItem

For Each drws In dg.Items

If drws.ItemIndex <> dg.SelectedIndex Then

drws.Attributes.Add("onmouseover", "this.style.backgroundColor='#eeeeee'")
drws.Style("cursor") = "hand"
drws.Attributes.Add("onmouseout", "this.style.backgroundColor='white'")

End If

Next

dg.SelectedItem.Attributes.Remove("onmouseout")
dg.SelectedItem.Attributes.Remove("onmouseover")
dg.SelectedItem.Style("backgroundColor") = "#A3C2F0"

dg.SelectedItemStyle.BackColor = System.Drawing.Color.FromArgb(163, 194, 240)

End Sub


Public Sub BindData()

'Check current supplier and view style
'Retrieves list of Tier1 categories/vendors based on current view

Dim wcRequest As New System.Net.WebClient
Dim xmlReader As System.Xml.XmlTextReader
Dim xmlDataSet As New DataSet
Dim bytResponse As Byte()
Dim stResponse As String
Dim nvValues As New Specialized.NameValueCollection

nvValues.Add("type", ViewType)

If Tier <> 1 Then

nvValues.Add("tier" & (Tier - 1).ToString, ParentID)

End If

wcRequest.Headers.Add("Content-Type", "application/x-www-form-urlencoded")

bytResponse = wcRequest.UploadValues(System.Configuration.ConfigurationSettings.AppSettings.Item("itqURL") & "/catalogue.tier" & Tier, "POST", nvValues)
stResponse = System.Text.Encoding.ASCII.GetString(bytResponse)

xmlReader = New System.Xml.XmlTextReader(New IO.StringReader(stResponse))
xmlDataSet.ReadXml(xmlReader)
Me.dgCategory.DataSource = xmlDataSet.Tables("tier" & Tier.ToString)

Me.dgCategory.Columns(1).HeaderText = "Level " & Tier.ToString
Me.dgCategory.DataBind()

End Sub




********** THIS IS THE INSTANTIATION WITHIN THE MAIN ASPX ***********



Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

If Page.IsPostBack = False Then

Me.tabStrip.SelectedItemID = "Main"
BindTier1()
GridLevel4 = Me.LoadControl("spec_datagrid.ascx")
GridLevel4.HasChild = False
GridLevel4.ParentID = 3
GridLevel4.Tier = 1
GridLevel4.SelectedID = Nothing
GridLevel4.BindData()
GridLevel4.ID = "gl4"
Me.phMainGrid.Controls.Add(GridLevel4)

End If
End Sub

"cericoli" <>
NewsGroup User
Re: User Control events11/26/2003 6:20:50 AM

0

Anybody got any suggestions - problem still exists.

Some further info:

Usercontrol works perfectly if I instantiate it within the ascx page, rather than in the code behind file.

It appears as if when the page post backs, the control is not being reloaded at all. Obviously i can't reload the control everytime the main page loads, so am not sure.

help help help :)
"master4eva" <>
NewsGroup User
Re: User Control events12/12/2003 5:30:49 PM

0

I did have a long post before the power tripped out much earlier today. Now I am just going to recapture to what could be done, based from my previous experience. I need you to try this code in the page (just comment out your supplied code):

Protected Overides Sub OnInit(ByVal e As System.EventArgs)
If Page.IsPostBack = False Then
Me.tabStrip.SelectedItemID = "Main"
BindTier1()
GridLevel4 = Me.LoadControl("spec_datagrid.ascx")
GridLevel4.HasChild = False
GridLevel4.ParentID = 3
GridLevel4.Tier = 1
GridLevel4.SelectedID = Nothing
GridLevel4.BindData()
GridLevel4.ID = "gl4"
Me.phMainGrid.Controls.Add(GridLevel4)
End If

MyBase.OnInit(e)
End Sub

If it works, I will then take the time out to explain what is happening in this situation... that is if my assumption is correct.

PS: Sorry it took so long because I am experiencing network problems (all related since the storm that hit the east coast of South Africa). I have been trying to submit this for quite some time but this is a sort of test to narrow down the cause of the problem and relay it back to my ISP.
-- Justin Lovell
7 Items, 1 Pages 1 |< << Go >> >|


Free Download:













setting validaterequest="false" for an indivual web user control

support validation

server control producing dynamic images in vs.net visual designer

retrieve individual textbox values (custom server control)

teched europe has some good info for hosters

help required building server controls that are derive from compositebase and are databound template

document loader control

using a user control in a custom server control.

asp.net & sql server 2005

custom datagrid control help

rendering style with htmltextwriter

object reference not set to instance of object in event handler

passing a textbox value from ascx to aspx

template control

itemplate's instantiatein not firing

looping through objects inside a custom control

design view not available for userconrol when inheriting from custom class

dynamically assigned events to dynamic controls

help - rebuilding control hierarchy twice

create a new checkbox control

autoformat preview

look for server component to convert .doc into mhtml

adding an onclick event in a .vb class

setting an imagebutton to use an embedded resource image

inheritance and overriding property types

ensurechildcontrols and createchildcontrols

is it just me

programming right mouse clicks

can you control the formatting of the server control tags

adding behaviour to a adrotator control

can help me how to solve my a little complex control???

too much time!!!

how to catch unhandled exception in error event for custom control

develop a web custom control

efficient data persistence between postbacks

clearing/discovering control events

composite control regexvalidator on textbox problems

new server control rendering problem in vvisual studio.net problem.

redirecting site traffic and download managers

designer when inheriting from a based control

system.web.ui.webcontrols classes

problem with panel control viewstate

requesting request.urlreferrer in a user control (vb.net)

object reference not set to an instance of an object

conversion please help !!

how would you rate this

how to create a custom validator control ?

user control, bubble event to page

client side validation

stupid question, array to dropdown editor style in property browser?

   
  Privacy | Contact Us
All Times Are GMT