473,324 Members | 2,268 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,324 software developers and data experts.

Load usercontrol in notPage ispostback

Hi,
In page_load :

If Not Page.IsPostBack Then
Dim myUC As UserControl = LoadControl("ficheProspects.ascx")
myUC.ID = "FicheProspects1"
End If

In another Sub i need to find my control :

Dim myUC As UserControl = CType((FindControl("FicheProspects1")), UserControl)
Dim ucType As Type = myUC.GetType()
Dim monIdUC As System.Reflection.PropertyInfo = ucType.GetProperty("monId")
' Set the property
monIdUC.SetValue(myUC, dgAdminProspects.DataKeys(e.Item.ItemIndex), Nothing)

But i have don't succes to find it :(
Nov 19 '05 #1
4 3322
Once you've created it, you need to add it to the page somewhere. So use
a PlaceHolder or some other "container" control and call MyPlaceHolder.Controls.Add(myUC)

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi,
In page_load :
If Not Page.IsPostBack Then
Dim myUC As UserControl = LoadControl("ficheProspects.ascx")
myUC.ID = "FicheProspects1"
End If
In another Sub i need to find my control :

Dim myUC As UserControl = CType((FindControl("FicheProspects1")),
UserControl)
Dim ucType As Type = myUC.GetType()
Dim monIdUC As System.Reflection.PropertyInfo =
ucType.GetProperty("monId")
' Set the property
monIdUC.SetValue(myUC, dgAdminProspects.DataKeys(e.Item.ItemIndex),
Nothing)
But i have don't succes to find it :(


Nov 19 '05 #2
Look my problem :

PAGE ASPX :

#Region " - Page_Load - "
Public Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
monStyle.Text = Session("style")
bindData()
Session("selectionligne") = -1
End If
End Sub
#End Region

#Region " - bindData - "
Public Sub bindData()
daAdminProspects.Fill(Bts1)
dgAdminProspects.DataSource = myDataview
dgAdminProspects.DataBind()
End Sub
#End Region

#Region " - ItemDataBound - "
Private Sub dgClient_ItemDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dgAdminProspects.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
Dim imgDelete As ImageButton =
CType(e.Item.FindControl("imgDelete"), ImageButton)
CreateConfirmBox(imgDelete, "Attention, merci de confirmer
la suppression.")
End If
End Sub
#End Region

#Region " - ItemCommand - "
Private Sub dgAdminProspects_ItemCommand(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
dgAdminProspects.ItemCommand
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
If e.CommandName = "Select" Then
dgAdminProspects.EditItemIndex = -1
bindData()
End If
End If
End Sub

#End Region

#Region " - SelectedIndexChanged - "
Private Sub dgAdminProspects_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
dgAdminProspects.SelectedIndexChanged
If dgAdminProspects.SelectedIndex = Session("selectionLigne")
Then
dgAdminProspects.SelectedIndex = -1
Session("selectionLigne") = -1
bindData()
Else
'Pas le meme => initialise la session("selectionLigne")
Session("selectionLigne") = dgAdminProspects.SelectedIndex
End If
End Sub
#End Region

#Region " - PreRender - "
Private Sub dgAdminProspects_PreRender(ByVal sender As Object, ByVal
e As System.EventArgs) Handles dgAdminProspects.PreRender
If dgAdminProspects.SelectedIndex > -1 Then
Dim oDGItem As New DataGridItem(0, 0, ListItemType.Item)

Dim oCell As New TableCell
oCell.HorizontalAlign = HorizontalAlign.Left
oCell.ColumnSpan = dgAdminProspects.Columns.Count
oDGItem.Cells.Add(oCell)

Dim myUC As ficheProspects =
CType(Page.LoadControl("ficheProspects.ascx"), ficheProspects)
myUC.monId =
CType(dgAdminProspects.DataKeys(dgAdminProspects.S electedIndex),
Integer)

'Vérifie si la couleur est alternative
If dgAdminProspects.SelectedIndex Mod 2 <> 0 Then
myUC.backcouleur =
CType(dgAdminProspects.AlternatingItemStyle.BackCo lor,
System.Drawing.Color)
oCell.BackColor =
dgAdminProspects.AlternatingItemStyle.BackColor
End If

oCell.Controls.Add(myUC)
dgAdminProspects.Controls(0).Controls.AddAt(dgAdmi nProspects.SelectedInd
ex + 3, oDGItem)
End If
End Sub
#End Region
---------------------------------------------
USERCONTROL : i have a panel, a table, and a button

'Variable public pour communiquer avec la page .aspx
Private _backcouleur As System.Drawing.Color
Public Property backcouleur() As System.Drawing.Color
Get
Return _backcouleur
End Get
Set(ByVal Value As System.Drawing.Color)
_backcouleur = Value
End Set
End Property

Private _monId As Integer
Public Property monId() As Integer
Get
Return _monId
End Get
Set(ByVal Value As Integer)
_monId = Value
End Set
End Property

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' Changer le background des panel
panelProspects.BackColor = backcouleur
panelProspectsUpdate.BackColor = backcouleur

End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Response.Write("TEST")

End Sub

-----------------------------------------------
If i click the button in the userControl... it break my aspx datagrid
and it doesn't access to Private Sub Button1_Click

What is the solution to click use the button is the userControl ?

*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #3


You can see the demo here :
http://www.businessteamsystem.com/ad...prospects.aspx

Click on the icon in right and after the button

*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #4
I can't quite tell what's wrong about it. This code is different than you
roriginal post, though. This code seems to dynamically load the user control
in PreRender not Page_Load. The only thing I'd say about that is make sure
any dynamically loaded controls are recreated upon postback. You should probabaly
do this in Page_Load (or earlier) so that all of the control IDs are in line
with how the original page rendered so that when there is a postback things
will work.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Look my problem :

PAGE ASPX :

#Region " - Page_Load - "
Public Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
monStyle.Text = Session("style")
bindData()
Session("selectionligne") = -1
End If
End Sub
#End Region
#Region " - bindData - "
Public Sub bindData()
daAdminProspects.Fill(Bts1)
dgAdminProspects.DataSource = myDataview
dgAdminProspects.DataBind()
End Sub
#End Region
#Region " - ItemDataBound - "
Private Sub dgClient_ItemDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dgAdminProspects.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
Dim imgDelete As ImageButton =
CType(e.Item.FindControl("imgDelete"), ImageButton)
CreateConfirmBox(imgDelete, "Attention, merci de confirmer
la suppression.")
End If
End Sub
#End Region
#Region " - ItemCommand - "
Private Sub dgAdminProspects_ItemCommand(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
dgAdminProspects.ItemCommand
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
If e.CommandName = "Select" Then
dgAdminProspects.EditItemIndex = -1
bindData()
End If
End If
End Sub
#End Region

#Region " - SelectedIndexChanged - "
Private Sub dgAdminProspects_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
dgAdminProspects.SelectedIndexChanged
If dgAdminProspects.SelectedIndex = Session("selectionLigne")
Then
dgAdminProspects.SelectedIndex = -1
Session("selectionLigne") = -1
bindData()
Else
'Pas le meme => initialise la session("selectionLigne")
Session("selectionLigne") = dgAdminProspects.SelectedIndex
End If
End Sub
#End Region
#Region " - PreRender - "
Private Sub dgAdminProspects_PreRender(ByVal sender As Object,
ByVal
e As System.EventArgs) Handles dgAdminProspects.PreRender
If dgAdminProspects.SelectedIndex > -1 Then
Dim oDGItem As New DataGridItem(0, 0, ListItemType.Item)
Dim oCell As New TableCell
oCell.HorizontalAlign = HorizontalAlign.Left
oCell.ColumnSpan = dgAdminProspects.Columns.Count
oDGItem.Cells.Add(oCell)
Dim myUC As ficheProspects =
CType(Page.LoadControl("ficheProspects.ascx"), ficheProspects)
myUC.monId =
CType(dgAdminProspects.DataKeys(dgAdminProspects.S electedIndex),
Integer)

'Virifie si la couleur est alternative
If dgAdminProspects.SelectedIndex Mod 2 <> 0 Then
myUC.backcouleur =
CType(dgAdminProspects.AlternatingItemStyle.BackCo lor,
System.Drawing.Color)
oCell.BackColor =
dgAdminProspects.AlternatingItemStyle.BackColor
End If
oCell.Controls.Add(myUC)

dgAdminProspects.Controls(0).Controls.AddAt(dgAdmi nProspects.SelectedI
nd
ex + 3, oDGItem)
End If
End Sub
#End Region
---------------------------------------------
USERCONTROL : i have a panel, a table, and a button
'Variable public pour communiquer avec la page .aspx
Private _backcouleur As System.Drawing.Color
Public Property backcouleur() As System.Drawing.Color
Get
Return _backcouleur
End Get
Set(ByVal Value As System.Drawing.Color)
_backcouleur = Value
End Set
End Property
Private _monId As Integer
Public Property monId() As Integer
Get
Return _monId
End Get
Set(ByVal Value As Integer)
_monId = Value
End Set
End Property
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' Changer le background des panel
panelProspects.BackColor = backcouleur
panelProspectsUpdate.BackColor = backcouleur
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click

Response.Write("TEST")

End Sub

-----------------------------------------------
If i click the button in the userControl... it break my aspx datagrid
and it doesn't access to Private Sub Button1_Click
What is the solution to click use the button is the userControl ?

*** Sent via Developersdex http://www.developersdex.com ***


Nov 19 '05 #5

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

Similar topics

2
by: Ivan G. | last post by:
Hi. How System.Web.UI.UserControl knows that it is really loaded at first time? I mean from where IsPostBack property value is extracted? Thanx.
0
by: Josema | last post by:
Hi to all, I have a webform.aspx and inside i have a dropdown list with autopostback and a place holder... Depending of the selected index that the user selects in the dropdownlist i load a...
1
by: huobazi | last post by:
a uscontrol test.ascx have a dropdownlist web control the dropdownlist's AutoPostBack property is set "true" but when i use Loadcontrol("test.ascx") in a aspx fiel's Page_Load event the...
1
by: Marcel Balcarek | last post by:
I create a user control dynamically: Dim newCriteriaControl As CriteriaTextBoxUserControl = CType(Me._page.LoadControl("CriteriaTextBoxUserControl.ascx"), CriteriaTextBoxUserControl) ...
1
by: Reza Nabi | last post by:
Bakground: I have a webform (LoadCtl.aspx) which loads the user control to a placeholder dynamically based on the ctlName querystring passed in the URL. Webform (LoadCtl.aspx) also passes a...
2
by: Sascha | last post by:
Hi there, I searched carefully through the web before finally deciding to post this message, because I could not find a solution for my problem. Hopefully someone will have a hint or explanation...
2
by: **Developer** | last post by:
I have a Form (FV&C) containing a userconrtrol (CF&E) I do a ShowDialog for the form and the form's Load calls a method of the UserControl. The first time I do this the usercontrol appears on...
6
by: p.mc | last post by:
Hi all, I'm having major problems with a userControl which contains a datagrid. My problem concerns data binding. The Page_Load() procedure calls the DataBind procedure to bind the datagrid...
2
by: Franky | last post by:
Threre is a Form containing a usercontrol In the form's Load event it references a usercontrol property, say, zz The first showdialog(formx) causes 1 usercontrol_load event 2 form_load event...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shćllîpôpď 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.