[Mono-list] unable to bind text to web control in a user control

Gonzalo Paniagua Javier gonzalo at ximian.com
Sun Oct 2 23:39:39 EDT 2005


On Sun, 2005-10-02 at 08:46 -0500, Carl Olsen wrote:
> I'm not getting any errors.  It is displaying HTML where the web control
> should be and it's not setting the values.  I tried your code, and I'm still
> getting nothing.

And the same thing happens when you run route test under MS.

Your error is that you're using 'Src' in:
<%@ Register TagPrefix="uc1" TagName="TestUserControl"
Src="Controls/TestUserControl.ascx" %>

When you do that, you won't get the behavior you expect, as
TestUserControl.ascx.cs will not be used at all. If you want to kee that
@Register in the page as it is, you should include most of
TestUserControl.ascx.cs inside a '<script runat="server">' in
TestUserControl.ascx. I'm attaching this one.

The other options that you might use is to have the .ascx use 'Inherit'
instead of 'Src' and have the current TestUserControl.ascx.cs compiled
into a dll that would be in the 'bin' directory.

-Gonzalo

-------------- next part --------------
<%@ Control Language="c#" AutoEventWireup="false" Src="TestUserControl.ascx.cs" %>
<script runat="server">
                private void Page_Load(object sender, System.EventArgs e)
                {
                        Label1.Text = "Hello";
                        HyperLink1.Text = "Again";
                        HyperLink1.NavigateUrl =
"http://www.carl-olsen.com/";
                }

                override protected void OnInit(EventArgs e)
                {
                        InitializeComponent();
                        base.OnInit(e);
                }
                
                private void InitializeComponent()
                {
                        this.Load += new
System.EventHandler(this.Page_Load);

                }
</script>
<p><asp:label id="Label1" runat="server">Label</asp:label></p>
<p><asp:hyperlink id="HyperLink1" runat="server">HyperLink</asp:hyperlink></p>



More information about the Mono-list mailing list