User Control without Visual Studio

Discussion in 'ASP .Net' started by mivhaelveloz, Apr 30, 2006.

  1. mivhaelveloz

    mivhaelveloz Guest

    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>
    mivhaelveloz, Apr 30, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wh
    Replies:
    2
    Views:
    504
    Cowboy \(Gregory A. Beamer\)
    Jan 16, 2004
  2. Thirumalai
    Replies:
    0
    Views:
    647
    Thirumalai
    May 22, 2006
  3. rockdale
    Replies:
    1
    Views:
    598
    Juan T. Llibre
    Aug 23, 2006
  4. xman
    Replies:
    0
    Views:
    480
  5. xman
    Replies:
    1
    Views:
    588
    Victor Bazarov
    Aug 17, 2005
Loading...

Share This Page