User Control without Visual Studio

M

mivhaelveloz

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top