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

Рассматриваются вопросы создания веб приложений с применением ASP.NET / VB.NET технологии.
The problems of creating web applications using ASP.NET / VB.NET technology.
olgbbfrm
Site Admin
Posts: 21
Joined: Wed Nov 18, 2015 1:05 am

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

Postby olgbbfrm » Thu Nov 19, 2015 12:24 am

Добавление 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">
</asp:ContentPlaceHolder>
...


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" />
</asp:Content>


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") = "Наша баня. Сырдарьинская область."
        pnlImgs.Controls.Add(img1)