dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online Memberslily
Padma
Rakesh Chaubey
Minu
srirama
satyapriyanayak
Saranya
krishnagoluguri@gmail.com
sharmila
parthiban
chandramohan
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Forums » .NET » ASP.NET »

How to change the image dynamically in master page(using codebehind)


Posted Date: 25 Dec 2011      Posted By:: Ravi     Member Level: Silver    Member Rank: 1053     Points: 5   Responses: 1




Hi friends,

my master page is like the following

<asp:ContentPlaceHolder ID="Header" runat="server">
<asp:Image ID="imgHeader" runat="server" ImageAlign="Top" ImageUrl="/IMAGE/ravi1.jpg"/>


</asp:ContentPlaceHolder >

<br />
<br />

<asp:ContentPlaceHolder ID="Content1" runat="server">

</asp:ContentPlaceHolder>

<br />
<br />
<asp:ContentPlaceHolder ID="Footer" runat="server">
<asp:Image ID="Image1" runat="server" ImageAlign= "Bottom" ImageUrl="/IMAGE/redrose1.jpg"/>
</asp:ContentPlaceHolder>


in my content page is

<%@ Page Language="C#" MasterPageFile="~/ImageLayout.Master" AutoEventWireup="true" CodeBehind="Usemas.aspx.cs" Inherits="MasterPageApp.Usemas" %>


<asp:Content ContentPlaceHolderID = "Content1" runat="server">





<br />
<br />
<br />
<br />
<table>
<tr>

<td>
<asp:TextBox ID="txtHeader" runat="server" >

</asp:TextBox>

</td>
<td>
<asp:Button ID="btnHeader" runat="server" Text="Header" onclick="btnHeader_Click" />
</td>

</tr>



<tr>

<td>

<asp:TextBox ID="txtFooter" runat="server">

</asp:TextBox>

</td>
<td>

<asp:Button ID="btnFooter" runat="server" Text="Footer" onclick="btnFooter_Click"/>

</td>
</tr>


<tr>
<td colspan="2">
<asp:Button ID="btnChange" runat="server" Text="ImgCgange"
onclick="btnChange_Click" />
</td>

</tr>

</table>

</asp:Content>


In my content page have 2 texboxes and 2 browse buttons and one image change button.


i got the imageurl path in textbox using browse button

i put the imageurl path in session

Session["Header1"] = txtHeader.Text;
Session["Footer1"] = txtFooter.Text;


then i accessing the session in master page.


MASTER PAGE LOAD EVENT
{
string Head = Convert.ToString(Session["Header1"]);
string Foot = Convert.ToString(Session["Footer"]);

imgHeader.Imageurl=Head;
imgFooter.Imageurl=Foot;


}


But it's not working..

(my logic is i want to change the image in master page based on what i select in the content page textbox )




thanks and regards
Ravi.p










Responses

#648608    Author: Murulidhara K      Member Level: Bronze      Member Rank: 3616     Date: 26/Dec/2011   Rating: 2 out of 52 out of 5     Points: 4

If you want to change the image url which is used in master page, you can always do that by overriding the System.Web.UI.Page class method.

protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
// the following line is important
MasterPage master = this.Master;
// unfortunately, compiler warns us that master is not used

// Here find the control to which you want to change the image
// using master, which is the master page. You can identify the //control by using content id.
}



 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : Bind image type DB field to Image control
Previous : Timer Control in asp.net
Return to Discussion Forum
Post New Message
Category:

Related Messages



Follow us on Twitter: https://twitter.com/dotnetspider

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.