Page 1 of 1

Добавление image в Panel, размещенную в Web User Control.

Posted: Thu Nov 19, 2015 12:24 am
by olgbbfrm
Добавление image в Panel, размещенную в Web User Control на Master Page.

1. Получаем ссылку на Master Page;
2. Получаем ссылку на Web User Control, находящийся на Master Page;
3. Получаем ссылку на объект (в нашем примере Panel), расположенный внутри Web User Control;
4. Добавляем объект (в нашем примере img) на Panel.
Пример кода:
Master Page: MyFamily.master

Code: Select all

<%@ Master Language="VB" CodeFile="MyFamily.master.vb" Inherits="Master_Pages_MyFamily" %>
<asp:ContentPlaceHolder id="cphContent" runat="server">

Web User Control: MyFamilyMemberInfo.ascx

Code: Select all

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="MyFamilyMemberInfo.ascx.vb" nherits="FamilyMemberInfo" %>
<asp:Panel ID="pnlGallery" runat="server" ></asp:Panel>

Code: Select all

Web Page: MyFamily_OlegYakupov.aspx
<%@ Page Language="VB" MasterPageFile="~/Master Pages/MyFamily.master" AutoEventWireup="false" CodeFile="MyFamily_OlegYakupov.aspx.vb" Inherits="MyFamily_OlegYakupov" Title="Oleg Yakupov" StylesheetTheme="MyFamily"%>

<%@ Register Src="~/MyFamilyMemberInfo.ascx" TagName="FamilyMemberInfo" TagPrefix="OLEG"  %>
<asp:Content ID="Content1" ContentPlaceHolderID="cphContent" Runat="Server">
<OLEG:FamilyMemberInfo ID="FamilyMemberInfo1" runat="server" />

Code Behind of the Web Page: MyFamily_OlegYakupov.aspx.vb

Code: Select all

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim cph As ContentPlaceHolder
        cph = CType(Page.Master.FindControl("cphContent"), ContentPlaceHolder)
Dim pnlImgs As Panel
        pnlImgs = CType(cph.FindControl("FamilyMemberInfo1").FindControl("pnlGallery"), Panel)
        Dim img1 As Image = New Image
        img1.Attributes("src") = "images1/Oleg/600px_Nasha_Banya_2001002.jpg"
        img1.Attributes("style") = "height:200px; border-right-style:solid; border-right-width:10px; border-right-color:Green;"
        img1.Attributes("title") = "Наша баня. Сырдарьинская область."