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

load ascx and set properties

Hi,
[using asp.net 2.0 framework]
I'm using loadControl to load an ascx into a variable.
This works ok but I'm having to load the control into an Object
variable
e.g.
Dim aWidget As Object = Me.LoadControl("/assets/components/
Widget.ascx")

I'd like to be able to load it into a variable of the proper type so I
can set properties.

I'm pretty sure I could do this with the 1.1 framework simply by
changing the ascx class to public, but this doesn't work with 2.0

Many thanks,

Jul 20 '07 #1
5 2069
Hello ?

The type have to bee available at the current context.
Then you can use DirectCast to cast into the specific wanted type.

Dim aWidget As MyType =
DirectCast(Me.LoadControl("/assets/components/Widget.ascx"), MyType)

--
Gruss, Peter Bucher
Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET
Jul 20 '07 #2
Hi Peter,
thanks for your reply.
The problem I'm having is that even if the type is public I can't do:
Dim aWidget As MyType

I get "MyType" is not defined

I've worked a way round this problem just by adding the control to the
page, rather than loading it dynamically.

Thanks,
Joe

http://www.ratemyband.co.uk

Jul 20 '07 #3
Hi Joe

lies the control in the same namespace, and if not: are you importing these
ones?

--
Gruss, Peter Bucher
Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET
Jul 20 '07 #4
Hi Peter,
it's in the same project, and I haven't set a specific namespace.
If I look at the class view I don't see my class

It's defined like this
Public Class myWidget
Inherits System.Web.UI.UserControl

and it's in a folder /assets/components/

Classes within /app_code are visisble, is this something to do with
it?

Thanks,
Joe

Jul 20 '07 #5
Hello Joe

Are you using a WebSite- or an WebApplications Project?
In a WebApplication Project, the namespaces would be generated automaticly
and like the folder they lies.
and it's in a folder /assets/components/
would give: Project.assets.components
Classes within /app_code are visisble, is this something to do with
it?
Both works on a WebApplication Project.

--
Gruss, Peter Bucher
Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET
Jul 20 '07 #6

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

Similar topics

2
by: Bonj | last post by:
H I want to make an ascx control with a DataGrid on it and make its bindings generic by using an ascx control, is there any way I can give each ascx control its own 'properties', like I want to make...
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...
6
by: Quentin | last post by:
I need to import an *;ascx, as an object, in my class, that is in myclass.vb. How can i do ? i saw the method LoadControl but i can't use it, or maybe i did wrong, if could help me it would be very...
5
by: djscratchnsniffing | last post by:
i know you can access an ascx's properties/methods from an aspx file. Let's say you have an aspx file with two code-behind files(ascx files). Can you access one of the ascx file's...
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...
1
by: Green | last post by:
Hi, All I need to dynamically load a user control and change some properties on the user control, and display in the aspx page. Unfortunately I failed, nothing appears. Please help me look at,...
1
by: ddelaney | last post by:
I've seen this posted before in many places, but have yet to find a real fix. I have a web application on dev server right now, and randomly, hours or days, it returns the expception posted below. ...
2
by: DC | last post by:
Hi, I want to keep all my layout information in the .ascx file of a UserControl. If I require layout related data in codebehind, I would usually use properties defined in the codebehind, e.g. ...
0
by: google | last post by:
Hi, I'm using loadControl to load an ascx into a variable. This works ok but I'm having to load the control into an Object variable e.g. Dim aWidget As Object =...
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...
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: 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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.