locked
I do not get this inherit in my UserControl RRS feed

  • Question

  • User-1004886483 posted

    I have the following UserControl :

    Per_Fiche.ascx

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="Per_Fiche.ascx.cs" Inherits="UserControls_PersonnePhysique_Per_Fiche" %>
    <table>
        <br />
        <tr>
            <td>
                Login (*) :
            </td>
            <td>
                <asp:TextBox runat="server" ID="PerLogin"></asp:TextBox>
            </td>
            <td>
                Mot de passe (*) :
            </td>
            <td>
                <asp:TextBox runat="server" ID="PerPassword" TextMode="Password"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td>
            </td>
            <td>
                Confirmer mot de passe (*) :
            </td>
            <td>
                <asp:TextBox runat="server" ID="PerPasswordConfirme" TextMode="Password"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Nom (*) :
            </td>
            <td>
                <asp:TextBox runat="server" ID="PerNom"></asp:TextBox>
            </td>
            <td>
                Prénom (*) :
            </td>
            <td>
                <asp:TextBox runat="server" ID="PerPrenom"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Civilite (*) :
            </td>
            <td>
                <asp:DropDownList runat="server" ID="PerCivilite" CssClass="DropDown">
                </asp:DropDownList>
            </td>
            <td>
                Profile (*) :
            </td>
            <td>
                <asp:DropDownList runat="server" ID="PerProfil" CssClass="DropDown">
                </asp:DropDownList>
            </td>
        </tr>
        <tr>
            <td>
                Courriel :
            </td>
            <td>
                <asp:TextBox runat="server" ID="PerMail"></asp:TextBox>
            </td>
            <td>
                Téléphone (1) :
            </td>
            <td>
                <asp:TextBox runat="server" ID="PerTelephone1"></asp:TextBox>
            </td>
        </tr>
        
        <tr>
            <td>
                Téléphone (2) :
            </td>
            <td>
                <asp:TextBox runat="server" ID="PerTelephone2"></asp:TextBox>
            </td>
            <td>
                Téléphone (3) :
            </td>
            <td>
                <asp:TextBox runat="server" ID="PerTelephone3"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Fax :
            </td>
            <td>
                <asp:TextBox runat="server" ID="PerFax"></asp:TextBox>
            </td>
        </tr>
    </table>

    Per_Fiche.ascx.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using MYFIRSTAPP.Domaine;
    
    public partial class UserControls_PersonnePhysique_Per_Fiche : MYFIRSTAPPUserControl
    {
        
        #region Evenements liés à la Page [PERMANENT]
    
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            InitialiserParametres();
            ConstruireBoutons();
            ConstruireListeControles();
            TraiterControles();
        }
        #endregion
    
        #region Méthode Recupération des Parametres [MIXTE]
    
        /// <summary>
        /// Initialisation des paramètres du formulaire
        /// </summary>
        private void InitialiserParametres()
        {
            try
            {
             
            }
            catch (Exception _e)
            {
            }
        }
    
        #endregion
    
        #region Construction des boutons [PERMANENT]
    
        /// <summary>
        /// Construction des boutons situés en pied de formulaire
        /// </summary>
        private void ConstruireBoutons()
        {
            try
            {
            }
            catch (Exception _e)
            {
            }
        }
    
        #endregion
    
        #region Contruction de la liste des contrôles [CONTEXTUEL]
    
        /// <summary>
        /// Construire les contrôles
        /// </summary>
        private void ConstruireListeControles()
        {
            try
            {
                
            }
            catch (Exception _e)
            {
            }
        }
    
        #endregion
    
        #region Traitement des controles [PERMANENT]
        /// <summary>
        /// Activation (desactivation) 
        /// </summary>
        private void TraiterControles()
        {
            try
            {
                MyfirstappControlsTools.TraiterControles(MYFIRSTAPPControles, Page);
            }
            catch (Exception _e)
            {
                TraiterErreur(_e);
            }
        }
        #endregion
    }

    Why it inherit to this : MYFIRSTAPPUserControl and what it does?

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Web.UI;
    using System.Text;
    using MYFIRSTAPP.Domaine;
    using MYFIRSTAPP.Services;
    using MYFIRSTAPP.Services.Logging;
    using MYFIRSTAPP.Common.Exceptions;
    using MYFIRSTAPP.Common.Exceptions.ExceptionsManagement;
    
    /// <summary>
    /// Description résumée de MYFIRSTAPPUserControl
    /// </summary>
    public class MYFIRSTAPPUserControl : System.Web.UI.UserControl
    {
    
        #region Properties
    
        #region Public
    
        /// <summary>
        /// Message d'erreur
        /// </summary>
        /// 
        public MyfirstappEntite Entite = null;
        public long EntiteID = long.MinValue;
        public long UtilisateurId = 1; //long.MinValue;
        public int UtilisateurProfil = 0; 
        public string Erreur;
        public List<MYFIRSTAPPControle> MYFIRSTAPPControles = new List<MYFIRSTAPPControle>();
        public bool IsDroit = false;
        public bool IsModifiable = true;
    
    
        #endregion
    
        #endregion
    
        #region Constructeur
    
        public MYFIRSTAPPUserControl()
        {
            Initialize();
        }
            
    
        #endregion
    
        #region Méthodes d'initialisation
        /// <summary>
        /// Make the base of the form
        /// </summary>
        private void Initialize()
        {
            try
            {
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        
        #endregion
    
        #region Méthodes de traitement de la log
    
        #region Méthode pour récupérer un message d'erreur
        /// <summary>
        /// Méthode permettant de récupérer un message d'erreur dans le fichier de ressource commun
        /// </summary>
        /// <param name="clef">Clef du message</param>
        /// <returns>Message d'erreur correspondant</returns>
        public string MessagesErreurs(string clef)
        {
            return MyfirstappBase.MessagesErreurs(clef);
        }
        #endregion
    
        protected void TraiterErreurs(MyfirstappExceptionCollection erreurs)
        {
            Panel ZoneDeLog = (Panel)MyfirstappControlsTools.TrouverControle(Page, "Log");
            foreach (MyfirstappException ex in erreurs)
            {
                Log.TraiterErreur(ex, ZoneDeLog);
            }
        }
    
        protected void TraiterWarnings(MyfirstappExceptionCollection warnings)
        {
            Panel ZoneDeLog = (Panel)MyfirstappControlsTools.TrouverControle(Page, "Log");
            foreach (MyfirstappException w in warnings)
            {
                TraiterWarning(w.Message, ZoneDeLog);
            }
        }
    
        protected void TraiterErreur(Exception e, params object[] contexte)
        {
            Type _typeException = e.GetType();
            if (_typeException.IsSubclassOf(typeof(MyfirstappMetierException)) ||
                _typeException == typeof(MyfirstappMetierException))
            {
                Erreur = e.Message;
                ExceptionManager.Publish(e);
            }
            else if (_typeException.IsSubclassOf(typeof(MyfirstappTechniqueException)) ||
                _typeException == typeof(MyfirstappTechniqueException))
            {
                Erreur = e.Message;
                ExceptionManager.Publish(e);
            }
    
            else
            {
                if (contexte != null && contexte.Length > 0)
                {
                    MyfirstappTechniqueException _e = new MyfirstappTechniqueException(MessagesErreurs("ErreurImprevue"), e);
    
                    StringBuilder _clef = null;
                    StringBuilder _valeur = null;
                    for (int _i = 0; _i < contexte.Length; _i++)
                    {
                        _valeur = new StringBuilder();
                        if (contexte[_i] != null)
                        {
                            _valeur.Append(contexte[_i].ToString()).Append(
                                " (de type ").Append(contexte[_i].GetType().Name).Append(")");
                        }
                        else
                        {
                            _valeur.Append("null");
                        }
                        _clef = new StringBuilder();
                        _clef.Append("Contexte_").Append(_i.ToString());
                        _e.AdditionalInformation.Add(_clef.ToString(), _valeur.ToString());
    
                    }
                    ExceptionManager.Publish(_e);
                }
                else
                {
                    ExceptionManager.Publish(e);
                }
                Erreur = MessagesErreurs("ErreurImprevue");
            }
    
            Panel ZoneDeLog = (Panel)MyfirstappControlsTools.TrouverControle(Page, "Log");
            Log.TraiterErreur(e, ZoneDeLog);
            UpdatePanel uZoneDeLog = (UpdatePanel)MyfirstappControlsTools.TrouverControle(Page, "ZoneDeLog");
            uZoneDeLog.Update();
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <param name="info"></param>
        /// <param name="contexte"></param>
        protected void TraiterInformation(string info, params object[] contexte)
        {
            Panel ZoneDeLog = (Panel)MyfirstappControlsTools.TrouverControle(Page, "Log");
            Log.TraiterInformation(info, ZoneDeLog);
            UpdatePanel uZoneDeLog = (UpdatePanel)MyfirstappControlsTools.TrouverControle(Page, "ZoneDeLog");
            uZoneDeLog.Update();
        }
    
        protected void TraiterWarning(string warning, params object[] contexte)
        {
            Panel ZoneDeLog = (Panel)MyfirstappControlsTools.TrouverControle(Page, "Log");
            Log.TraiterWarning(warning, ZoneDeLog);
            UpdatePanel uZoneDeLog = (UpdatePanel)MyfirstappControlsTools.TrouverControle(Page, "ZoneDeLog");
            uZoneDeLog.Update();
        }
    
        protected void TraiterException(Exception e, params object[] contexte)
        {
            Type _typeException = e.GetType();
            if (_typeException.IsSubclassOf(typeof(MyfirstappMetierException)) ||
                _typeException == typeof(MyfirstappMetierException))
            {
                Erreur = e.Message;
                ExceptionManager.Publish(e);
            }
            else if (_typeException.IsSubclassOf(typeof(MyfirstappTechniqueException)) ||
                _typeException == typeof(MyfirstappTechniqueException))
            {
                Erreur = e.Message;
                ExceptionManager.Publish(e);
            }
    
            else
            {
                if (contexte != null && contexte.Length > 0)
                {
                    MyfirstappTechniqueException _e = new MyfirstappTechniqueException(MessagesErreurs("ErreurImprevue"), e);
    
                    StringBuilder _clef = null;
                    StringBuilder _valeur = null;
                    for (int _i = 0; _i < contexte.Length; _i++)
                    {
                        _valeur = new StringBuilder();
                        if (contexte[_i] != null)
                        {
                            _valeur.Append(contexte[_i].ToString()).Append(
                                " (de type ").Append(contexte[_i].GetType().Name).Append(")");
                        }
                        else
                        {
                            _valeur.Append("null");
                        }
                        _clef = new StringBuilder();
                        _clef.Append("Contexte_").Append(_i.ToString());
                        _e.AdditionalInformation.Add(_clef.ToString(), _valeur.ToString());
    
                    }
                    ExceptionManager.Publish(_e);
                }
                else
                {
                    ExceptionManager.Publish(e);
                }
                Erreur = MessagesErreurs("ErreurImprevue");
            }
    
            Panel ZoneDeLog = (Panel)MyfirstappControlsTools.TrouverControle(Page, "Log");
            Log.TraiterException(e, ZoneDeLog);
            UpdatePanel uZoneDeLog = (UpdatePanel)MyfirstappControlsTools.TrouverControle(Page, "ZoneDeLog");
            uZoneDeLog.Update();
        }
    
        protected void AddLog(EnumLogType type, string message)
        {
            Msg msg = new Msg(type, message+"<br />");
            Panel ZoneDeLog = (Panel)MyfirstappControlsTools.TrouverControle(Page, "Log");
            Log.AddLog(msg, ZoneDeLog);
            UpdatePanel uZoneDeLog = (UpdatePanel)MyfirstappControlsTools.TrouverControle(Page, "ZoneDeLog");
            uZoneDeLog.Update();
        }
    
        protected void ClearLogZone()
        {
            Panel ZoneDeLog = (Panel)MyfirstappControlsTools.TrouverControle(Page, "Log");
            ZoneDeLog.Controls.Clear();
            UpdatePanel uZoneDeLog = (UpdatePanel)MyfirstappControlsTools.TrouverControle(Page, "ZoneDeLog");
            uZoneDeLog.Update();
        }
    
        #endregion
    }
    

    Friday, December 15, 2017 10:55 AM

Answers

  • User347430248 posted

    Hi devquestions...,

    do you mean why the user control added to your web page?

    if yes, then it was added by you or someone to use the User Control in your Webpage.

    so that you can use the functionality of user control on that page.

    In Software Development, everybody is talking about reusability. A UserControl also provides for reusability. In other words, we can create and edit in one thing and get results everywhere, wherever you use the item.

    For example we have an e-mail form or a contact us form and I want to use it in 4 different pages in various parts. And if the client requirnments change then I just make the changes in one place and automatically the changes will be done in all forms. So for this we can use a UserControl. <sub></sub><sup></sup>

    so that's why it is inherit to your web page.

    if you don't want that functionality in your page then you can remove the UserControl from that page.

    you can also refer the links below may give you more information regarding UserControl.

    ASP.NET User Controls Overview

    How to: Create an ASP.NET User Control

    How to: Include a User Control in an ASP.NET Web Page

    UserControl in ASP.Net

    if you are saying that another user control is added to your user control then you are using a nested user control.

    so that when page get load you can use the functionality of both user controls.

    How to implement nested Web user controls in ASP.NET by using Visual Basic .NET

    Regards

    Deepak

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 18, 2017 8:44 AM