473,938 Members | 1,881 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Load usercontrol in notPage ispostback

Hi,
In page_load :

If Not Page.IsPostBack Then
Dim myUC As UserControl = LoadControl("fi cheProspects.as cx")
myUC.ID = "FicheProspects 1"
End If

In another Sub i need to find my control :

Dim myUC As UserControl = CType((FindCont rol("FicheProsp ects1")), UserControl)
Dim ucType As Type = myUC.GetType()
Dim monIdUC As System.Reflecti on.PropertyInfo = ucType.GetPrope rty("monId")
' Set the property
monIdUC.SetValu e(myUC, dgAdminProspect s.DataKeys(e.It em.ItemIndex), Nothing)

But i have don't succes to find it :(
Nov 19 '05 #1
4 3362
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.C ontrols.Add(myU C)

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

Dim myUC As UserControl = CType((FindCont rol("FicheProsp ects1")),
UserControl)
Dim ucType As Type = myUC.GetType()
Dim monIdUC As System.Reflecti on.PropertyInfo =
ucType.GetPrope rty("monId")
' Set the property
monIdUC.SetValu e(myUC, dgAdminProspect s.DataKeys(e.It em.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.EventArg s) Handles MyBase.Load
If Not Page.IsPostBack Then
monStyle.Text = Session("style" )
bindData()
Session("select ionligne") = -1
End If
End Sub
#End Region

#Region " - bindData - "
Public Sub bindData()
daAdminProspect s.Fill(Bts1)
dgAdminProspect s.DataSource = myDataview
dgAdminProspect s.DataBind()
End Sub
#End Region

#Region " - ItemDataBound - "
Private Sub dgClient_ItemDa taBound(ByVal sender As Object, ByVal e
As System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles
dgAdminProspect s.ItemDataBound
If e.Item.ItemType = ListItemType.It em Or e.Item.ItemType =
ListItemType.Al ternatingItem Then
Dim imgDelete As ImageButton =
CType(e.Item.Fi ndControl("imgD elete"), ImageButton)
CreateConfirmBo x(imgDelete, "Attention, merci de confirmer
la suppression.")
End If
End Sub
#End Region

#Region " - ItemCommand - "
Private Sub dgAdminProspect s_ItemCommand(B yVal source As Object,
ByVal e As System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles
dgAdminProspect s.ItemCommand
If e.Item.ItemType = ListItemType.It em Or e.Item.ItemType =
ListItemType.Al ternatingItem Then
If e.CommandName = "Select" Then
dgAdminProspect s.EditItemIndex = -1
bindData()
End If
End If
End Sub

#End Region

#Region " - SelectedIndexCh anged - "
Private Sub dgAdminProspect s_SelectedIndex Changed(ByVal sender As
Object, ByVal e As System.EventArg s) Handles
dgAdminProspect s.SelectedIndex Changed
If dgAdminProspect s.SelectedIndex = Session("select ionLigne")
Then
dgAdminProspect s.SelectedIndex = -1
Session("select ionLigne") = -1
bindData()
Else
'Pas le meme => initialise la session("select ionLigne")
Session("select ionLigne") = dgAdminProspect s.SelectedIndex
End If
End Sub
#End Region

#Region " - PreRender - "
Private Sub dgAdminProspect s_PreRender(ByV al sender As Object, ByVal
e As System.EventArg s) Handles dgAdminProspect s.PreRender
If dgAdminProspect s.SelectedIndex > -1 Then
Dim oDGItem As New DataGridItem(0, 0, ListItemType.It em)

Dim oCell As New TableCell
oCell.Horizonta lAlign = HorizontalAlign .Left
oCell.ColumnSpa n = dgAdminProspect s.Columns.Count
oDGItem.Cells.A dd(oCell)

Dim myUC As ficheProspects =
CType(Page.Load Control("ficheP rospects.ascx") , ficheProspects)
myUC.monId =
CType(dgAdminPr ospects.DataKey s(dgAdminProspe cts.SelectedInd ex),
Integer)

'Vérifie si la couleur est alternative
If dgAdminProspect s.SelectedIndex Mod 2 <> 0 Then
myUC.backcouleu r =
CType(dgAdminPr ospects.Alterna tingItemStyle.B ackColor,
System.Drawing. Color)
oCell.BackColor =
dgAdminProspect s.AlternatingIt emStyle.BackCol or
End If

oCell.Controls. Add(myUC)
dgAdminProspect s.Controls(0).C ontrols.AddAt(d gAdminProspects .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.EventArg s) Handles MyBase.Load
' Changer le background des panel
panelProspects. BackColor = backcouleur
panelProspectsU pdate.BackColor = backcouleur

End Sub
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) 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.EventArg s) Handles MyBase.Load
If Not Page.IsPostBack Then
monStyle.Text = Session("style" )
bindData()
Session("select ionligne") = -1
End If
End Sub
#End Region
#Region " - bindData - "
Public Sub bindData()
daAdminProspect s.Fill(Bts1)
dgAdminProspect s.DataSource = myDataview
dgAdminProspect s.DataBind()
End Sub
#End Region
#Region " - ItemDataBound - "
Private Sub dgClient_ItemDa taBound(ByVal sender As Object, ByVal e
As System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles
dgAdminProspect s.ItemDataBound
If e.Item.ItemType = ListItemType.It em Or e.Item.ItemType =
ListItemType.Al ternatingItem Then
Dim imgDelete As ImageButton =
CType(e.Item.Fi ndControl("imgD elete"), ImageButton)
CreateConfirmBo x(imgDelete, "Attention, merci de confirmer
la suppression.")
End If
End Sub
#End Region
#Region " - ItemCommand - "
Private Sub dgAdminProspect s_ItemCommand(B yVal source As Object,
ByVal e As System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles
dgAdminProspect s.ItemCommand
If e.Item.ItemType = ListItemType.It em Or e.Item.ItemType =
ListItemType.Al ternatingItem Then
If e.CommandName = "Select" Then
dgAdminProspect s.EditItemIndex = -1
bindData()
End If
End If
End Sub
#End Region

#Region " - SelectedIndexCh anged - "
Private Sub dgAdminProspect s_SelectedIndex Changed(ByVal sender As
Object, ByVal e As System.EventArg s) Handles
dgAdminProspect s.SelectedIndex Changed
If dgAdminProspect s.SelectedIndex = Session("select ionLigne")
Then
dgAdminProspect s.SelectedIndex = -1
Session("select ionLigne") = -1
bindData()
Else
'Pas le meme => initialise la session("select ionLigne")
Session("select ionLigne") = dgAdminProspect s.SelectedIndex
End If
End Sub
#End Region
#Region " - PreRender - "
Private Sub dgAdminProspect s_PreRender(ByV al sender As Object,
ByVal
e As System.EventArg s) Handles dgAdminProspect s.PreRender
If dgAdminProspect s.SelectedIndex > -1 Then
Dim oDGItem As New DataGridItem(0, 0, ListItemType.It em)
Dim oCell As New TableCell
oCell.Horizonta lAlign = HorizontalAlign .Left
oCell.ColumnSpa n = dgAdminProspect s.Columns.Count
oDGItem.Cells.A dd(oCell)
Dim myUC As ficheProspects =
CType(Page.Load Control("ficheP rospects.ascx") , ficheProspects)
myUC.monId =
CType(dgAdminPr ospects.DataKey s(dgAdminProspe cts.SelectedInd ex),
Integer)

'Virifie si la couleur est alternative
If dgAdminProspect s.SelectedIndex Mod 2 <> 0 Then
myUC.backcouleu r =
CType(dgAdminPr ospects.Alterna tingItemStyle.B ackColor,
System.Drawing. Color)
oCell.BackColor =
dgAdminProspect s.AlternatingIt emStyle.BackCol or
End If
oCell.Controls. Add(myUC)

dgAdminProspect s.Controls(0).C ontrols.AddAt(d gAdminProspects .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.EventArg s) Handles MyBase.Load
' Changer le background des panel
panelProspects. BackColor = backcouleur
panelProspectsU pdate.BackColor = backcouleur
End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e
As System.EventArg s) 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
2297
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
2588
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 usercontrol into the place holder... i dont know why im getting this error:
1
5332
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 dropdownlist which in the ascx can not run good it can not autopostback and can not call the OnselectedChange event. help me pls~~
1
2810
by: Marcel Balcarek | last post by:
I create a user control dynamically: Dim newCriteriaControl As CriteriaTextBoxUserControl = CType(Me._page.LoadControl("CriteriaTextBoxUserControl.ascx"), CriteriaTextBoxUserControl) myContainer.Add(newCriteriaControl) and the user control's load event executes on initial executon of the page. On a POST of the same page, the control is added as above, but the load event is not firing, nor is prerender.
1
1022
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 variable (targetId) in to the usercontrol (IntergySite.aspx) by calling its setter method. Currently, I am using if-then-else and hardcoded the User Control Object to do casting and call the setter method. Question: Is there any way I could load,...
2
4649
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 for me! I apologize for the length of this posting, but I wanted to make sure that I get an answer other than "Hey man, just use LoadControl!", because this is not what I want. The Task: Isolate a collection of web forms which are created as
2
2038
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 the form as I'd expect after the method had been run. The second time I do this the usercontrol appears on the form as if the usercontrols Load had last been run.
6
5752
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 to a DataSet. If i include an if statement to prevent the data binding from occuring on a page PostBack in the following way:
2
2958
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 which causes zz as expected the second showdialog(formx) causes 1 form_load event which causes zz as expected
0
10132
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
11103
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...
1
11284
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9854
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7378
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
6072
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
6290
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4901
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
4444
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.