He creado una clase en C# dentro de una biblioteca de clases y he agregado este control a default.aspx, pero mi código no activa el evento page_load. Aquí está el código:Page_Load no se activa en UserControl
¿Qué hago mal?
La página carga pero no muestra la etiqueta en la página. He agregado el control a la página correctamente sin ningún error. He añadido un evento con la etiqueta de registro allí.
etiqueta html: <RandoIntegerControls:RandomIntegerControl ID="RandomIntegerControl1" runat="server"></RandoIntegerControls:RandomIntegerControl>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
namespace CSIMedia.WebControls
{
public class RandomIntegerControl : PlaceHolder
{
private Label _Label;
public RandomIntegerControl()
{
}
private void Page_Load(Object sender, EventArgs e)
{
this._Label = new Label();
this.Controls.Add(this._Label);
this._Label.Text = "Enter random values:";
}
}
}
página Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register TagPrefix="RandoIntegerControls" Assembly="CSIMedia.WebControls" Namespace="CSIMedia.WebControls"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<RandoIntegerControls:RandomIntegerControl ID="RandomIntegerControl1" runat="server"></RandoIntegerControls:RandomIntegerControl>
</div>
</form>
</body>
</html>
¿Incluyó el archivo .ascx de su control personalizado en el archivo aspx que lo usa? – skaz
no lo eliminé. No he creado archivos ascx. He creado esta clase como un archivo class.cs y acabo de agregar esta clase de control a la página. pero he agregado la página default.aspx y todavía no tengo suerte. – redoc01
¿Puedes mostrar el código donde agregaste el control a la página? – skaz