getting error while setting imageURL to image ..whr i am doin wrong

Posted by Rickeybglr under ASP.NET on 7/26/2012 | Points: 10 | Views : 1476 | Status : [Member] | Replies : 7
i am getting error on below code "Object reference not set to an instance of an object." ..i have debugged the code strURL is not blanked

public void displayPic(string strURL)
{
if (!IsPostBack)
{
try
{
//imzProfilePic.ImageUrl ="~/App_Data/Images/UserImages/home.jpg"; /// ths is suppose to be in URL..i have checkd tht ths folder has the image
imzProfilePic.ImageUrl = strURL;
imzProfilePic.Visible = true;
}
catch (Exception ee)
{
ee.Message.ToString();
}

}
}




Responses

Posted by: Patel28rajendra on: 7/26/2012 [Member] Starter | Points: 25

Up
0
Down
Hi

put
imzProfilePic.Visible = true; 

above the
 imzProfilePic.ImageUrl = strURL;





R D Patel

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

Posted by: Rickeybglr on: 7/26/2012 [Member] Starter | Points: 25

Up
0
Down
still getting the same error

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

Posted by: Ranjeet_8 on: 7/26/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
The App_Data folder is a special folder reserved for data such as database files
and will NOT render out any contents on the web.
so plz change ur image location.

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

Posted by: Rickeybglr on: 7/26/2012 [Member] Starter | Points: 25

Up
0
Down
i tried ..gbut tht not workin.. itried in new way now its working ..but web page is not showing the image , it showing a red cross instead of image.
Image img1 = new Image();
img1.ImageUrl = "~/images/image1.jpg";
this.imzProfilePic.Visible = true;
this.imzProfilePic = img1;
imzProfilePic.Width=200;
imzProfilePic.Height = 200;

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

Posted by: Ranjeet_8 on: 7/26/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Hi..
try this.

// C#
    protected void Page_Load(object sender, EventArgs e)

{
if (!IsPostBack)
{
Image img = new Image();
img.ImageUrl = "images/1.jpg";
img.AlternateText = "Test image";
dv.Controls.Add(img);
}
}


// HTML

  <div id="dv" runat="server">

</div>


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

Posted by: Ranjeet_8 on: 7/26/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Hi.. Rickeybglr
if this post helps u, plz Mark As Answer

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

Posted by: Rickeybglr on: 7/26/2012 [Member] Starter | Points: 25

Up
0
Down
i tried the above.. still gettn the same error heheh.
but i have tried in a new way which has solved my problm thanks every1....for posting

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

Login to post response