what's wrong in this code..givin null exception. [Resolved]

Posted by Rickeybglr under ASP.NET on 8/20/2012 | Points: 10 | Views : 1385 | Status : [Member] | Replies : 4
protected void Page_Load(object sender, EventArgs e)
{

imzProPic.ImageUrl = "~/images/UserProfileDP/raj123/thumb_image4.jpg".ToString();
}

i have written this code in master page load event ..
path is correct ..but still at run time gettin null exception




Responses

Posted by: Vasanthmvp on: 8/20/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi,

i think you might have added the image control inside the placeholder of MasterPage.

Try this one:

Master1.Master

<asp:Image ID="img" runat="server" />
<asp:ContentPlaceHolder ID="contentplaceholder1" runat="server">

</asp:ContentPlaceHolder>


Master1.cs

protected void Page_Load(object sender, EventArgs e)
{

img.ImageUrl = "~/007.jpg"; or "~/007.jpg".ToString(); //007.jpg is my image name.

}


View it from the Default.aspx page that is under Master1.


Regards,

Awesome Coding !! :)

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rickeybglr on: 8/20/2012 [Member] Starter | Points: 25

Up
0
Down
hi Vasanthmvp,

yes i have place the image in contentplaceholder and this is required. wat i need to do is, i have to show user display pic on every page using the same master page. for this i have added the image in contentplace holder under left panel

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rickeybglr on: 8/20/2012 [Member] Starter | Points: 25

Up
0
Down
hey thanks mann my issue is resolved now and also learnt new thing thnks Vasanthmvp

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vasanthmvp on: 8/20/2012 [Member] Starter | Points: 25

Up
0
Down
There might be some conflicts raised between the placeholder id's.

As far as i know, to repeat the content on to all the pages. We place the required(in your case : image in the left panel) content in the master page out of the placeholder, and the content that we want to add/change explicitly on individual pages should be included in the respective placeholder(id same as in master page) of the asp page.

Placeholder in the sense, we are creating some space to hold the content that is specified in the individual pages, that is why we mention the placeholder id to the controls in aspx page... in which placeholder does these control should go under.

If i am wrong please correct me.

Regards,

Awesome Coding !! :)

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response