Simple User Control Problem

Posted by Community Admin on 04-Aug-2018 21:15

Simple User Control Problem

All Replies

Posted by Community Admin on 12-Sep-2011 00:00

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

Posted by Community Admin on 13-Sep-2011 00:00

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?

Posted by Community Admin on 13-Sep-2011 00:00

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?

This thread is closed