More in this section

Forums / Developing with Sitefinity / Simple User Control Problem

Simple User Control Problem

3 posts, 0 answered
  1. John S.
    John S. avatar
    126 posts
    Registered:
    09 Aug 2004
    12 Sep 2011
    Link to this post
    I created a very simple user control, uploaded, and created a toolbox item into a Sitefinity 4.2 installation. The control has a button that increments a counter and displays a label that says Hello World and the counter number

    The codebehind is as folows and I did not have to alter it

    Public Class ucHelloWorld
        Inherits System.Web.UI.UserControl
      
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      
        End Sub
      
        Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            HiddenField1.Value = HiddenField1.Value + 1
            Label1.Text = "Hello World " & HiddenField1.Value
        End Sub
    End Class

    The original ascx file was

    <%@ Control Language="vb" AutoEventWireup="false" CodeBehind="ucHelloWorld.ascx.vb" Inherits="OsUserControls.ucHelloWorld" %>
    <asp:Button ID="Button1" runat="server" Text="Button" />
    <asp:Label ID="Label1" runat="server"></asp:Label>
    <asp:HiddenField ID="HiddenField1" runat="server" Value="0" />

    however, in order to get bit to work I had to change the CodeBehind to CodeFile and remove OsUserControls from the Inherit parameter.  So the control that works is

    <%@ Control Language="vb" AutoEventWireup="false" CodeFile="ucHelloWorld.ascx.vb" Inherits="ucHelloWorld" %>
    <asp:Button ID="Button1" runat="server" Text="Button" />
    <asp:Label ID="Label1" runat="server"></asp:Label>
    <asp:HiddenField ID="HiddenField1" runat="server" Value="0" />

    Why is it I need to change these items?


    Thanks,
    John
  2. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    13 Sep 2011
    Link to this post
    SF3 was a website project where you could change code on a whim, but 4.x is a web app project which needs compilation for the code to work\update

    Does this article help at all perhaps?
  3. John S.
    John S. avatar
    126 posts
    Registered:
    09 Aug 2004
    13 Sep 2011
    Link to this post
    Thanks Steve.

    With that said, is there a problem with appoaching a user control in this way and just changing CodeBehind to CodeFile or am I asking for trouble?
3 posts, 0 answered