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

ASP.NET User Controls - missing something small?

Hiya
Im trying to get a user control working in mono/ASP.NET.

....I have no problem getting a basic control up and working and using
it declaratively in a hosting page's .aspx file.

But for the life of me I can't figure out how to access that control
from the hosting page's code behind file. That is, I would like to set
some of the properties of that control at runtime (say, in Page_Load)
instead of setting the to hardcoded values in the hosting page's aspx
file.

When following all the examples on the web on how to do this, it looks
like you should simply be able to declare a variable in the hosting
page's aspx.cs file of the class type of your control.. then just
reference that variable someplace like Page_Load. This blows up in
mono - the reference to your control class type is not recognized in
the hosting file's aspx.cs file. (I believe Visual Studio precompiles
your control class for you and add's whatever is needed in your hosting
file so that it recognizes your control class)

At this point I'm led me to believe that I need my user control to be
compiled and sitting in my applications /bin directory and to add the
appropriate "using" statement to the top of the hosting page's aspx.cs
file. .. so that when my hosting page's aspx.cs file is compiled, the
compiler will recognize my class type and let me access it
programatically.

I compiled my control class, and made a few changes to the directives
at the top of my control's acsx page as well as the hosting page's aspx
page, but now XSP is throwing an internal server error.

ANY HELP WOULD BE APPRECIATED!!

Here are tiny snippets of code to illustrate what I am doing

===== the control ======
=== ascx.cs ===

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MPI.Util.LoggerTypes;

namespace MPI.Testing {

public class FilterList : UserControl {
public string MyText {
get { return yyy.Text; }
set { yyy.Text = value; }
}
}

}

=== ascx ===
<%@ Control language="c#" Inherits="MPI.Testing.FilterList"
AutoEventWireup="true" %>

<asp:Panel id="xxx" runat="server" borderStyle="dotted">
<asp:Label id="yyy" runat="server" text="default" />
</asp:Panel>

============= the hosting page ============

=== aspx.cs ===
using System;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using MPI.Testing;

namespace MPI {

public class TestPage : Page {

FilterList f;

protected void Page_Load(object sender, EventArgs e) {
f.MyText = "yippee!";
}
protected void Page_PreRender(object sender, EventArgs e) {
}
}

}

=== aspx ===
<%@ Page language="c#" src="test.aspx.cs" Inherits="MPI.TestPage"
AutoEventWireup="true" %>
<%@ Register TagPrefix="mpi" TagName="test" assembly="filterlist" %>

<form id="theForm" method="post" runat="server">

<mpi:test id="foo" runat="server" MyText="zot"/>

</form>

May 1 '06 #1
0 1076

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

Similar topics

6
by: Jim | last post by:
I have a user control that I am dynamically loading into an aspx page. When I fill out the text boxes and submit the form using a command button on the aspx page I lose the value from the user...
20
by: Alan Silver | last post by:
Hello, In classic ASP, I used to use two include files on each page, one before and one after the main content, to provide a consistent layout across a web site. That way I could just change the...
2
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
1
by: Ramesh | last post by:
Hello all, I have a form in which I'm trying to load a user control depending on some user choice, and my control's events are not firing properly. Here's a completely stripped down repro of the...
8
by: | last post by:
I'm looking for some design guidance on a collection of projects I'm working on. The project involves a bunch of websites constructed out of a collection of user controls. Different user...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.