473,378 Members | 1,404 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.

Usercontrol in Page_Load

Hello,

I don't know how UserControl should work:

If I put MyPlaceHolder.Controls.Add(MyUsrControl) inside "If (Not
Page.IsPostBack) Then", when MyWebForm is loaded, the usercontrol is
not loaded.
Why not?

Example:

Public Class MyWebForm
Inherits System.Web.UI.Page

Private MyUsrControl As Control =
LoadControl("../myUsrControl.ascx")

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If (Not Page.IsPostBack) Then
MyPlaceHolder.Controls.Add(MyUsrControl) ' Does not work.
Why?
End If

MyPlaceHolder.Controls.Add(MyUsrControl) ' Here it works
End Sub

Sep 30 '06 #1
1 1335
You have to add the control to the page every time, not just the first
time the page is loaded.

Big Charles wrote:
Hello,

I don't know how UserControl should work:

If I put MyPlaceHolder.Controls.Add(MyUsrControl) inside "If (Not
Page.IsPostBack) Then", when MyWebForm is loaded, the usercontrol is
not loaded.
Why not?

Example:

Public Class MyWebForm
Inherits System.Web.UI.Page

Private MyUsrControl As Control =
LoadControl("../myUsrControl.ascx")

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If (Not Page.IsPostBack) Then
MyPlaceHolder.Controls.Add(MyUsrControl) ' Does not work.
Why?
End If

MyPlaceHolder.Controls.Add(MyUsrControl) ' Here it works
End Sub
Oct 4 '06 #2

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

Similar topics

1
by: jralford | last post by:
Hi, Another question from a C# newbie: I have a usercontrol class that includes a customized control. Now, if I create an instance of the class, and click on it, a click event is raised for the...
3
by: Iain | last post by:
Hi I have page (testCal.aspx) that contains a usercontrol (custCalendar.ascx) - see below signature for code. The UC contains a linkbutton which which when clicked, posts back and displays a...
4
by: Harry | last post by:
Hello, I have a page with a RadioButtonList and a PlaceHolder control. The RadioButtonList's AutoPostBack attribute is set to TRUE and its SelectedIndexChanged event loads one of three...
6
by: Pete Davis | last post by:
I'm fairly weak with ASP.NET. What I'm trying to do is pass an attribute to a UserControl. The attribute is a value from the CodeBehind for the page. So in my .aspx I have the following: ...
4
by: sebastien | last post by:
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 :
4
by: Alexander Widera | last post by:
How can I include an usercotrol into an other usercontrol... for example: <UserControl:First runat="server" id="firstUC" content="..." /> and i want to refer an other UserControl (e.g. called...
1
by: Will Gillen | last post by:
I know this has probably been asked before, but I can't seem to find a solid answer in any of the archives. First, before my question, please forgive my limited knowledge of the event lifecycle...
4
by: Sam Martin | last post by:
Hi, I have got a User Control that contains for the sake of argument, a single DataList control. eg. <asp:DataList id="DataListMain" runat="server" RepeatDirection="Horizontal"...
5
by: seal | last post by:
OK, I am trying to fire an event from a usercontrol that tells the page when a checkbox was clicked. Here is the control and when I try and wire up the page to catch the event, my event is not...
4
by: igotyourdotnet | last post by:
I have a dropdown on my page and I want to define what should be selected in the drop down when the page loads. I have a session variable I'm setting to do this. I can get the selected value and...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.