By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,696 Members | 2,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,696 IT Pros & Developers. It's quick & easy.

User Control without Visual Studio

P: n/a
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. However, I am not
exactly sure what it adds
to the files to make this happen automagically. I would love to know!)
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>

Apr 30 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.