0

I am using a asyncfileUpload control in my page, and that page is derived from a master page. My motive to use this control is only to upload an image and show that image on the same page. But when i am trying to upload an image, i am getting an Exception i.e.: "Unhandled Exception: $get("imgUpload") is null". I am using the following function on ClientUploadComplete:

<script type="text/javascript">
     function uploadComplete(sender, args) {
         var FileName = args.get_fileName();
         $get("imgUpload").src = "../ajax/upload/" + FileName;
     }
</script>

and i have also set the ClientIDMode=AutoID.

And i am using the following code under the UploadedComplete event:

 protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
    string strPath = MapPath("~/ajax/upload/") + Path.GetFileName(e.FileName);
    AsyncFileUpload1.SaveAs(strPath);
    imgUpload.ImageUrl = strPath;
}

In a normal page, when I try the above It is working correctly but in case of Derived page (from Master Page) it is arising the exception.

Please help me out here to fix this problem.

With Regards, Ravindra Kumar

1 Answers1

0

AutoID will rename the control based on rendering order, so when the master page is added in, it changes everything. Have you taken a look at your rendered source to verify the rendered control id? Try changing ClientIDMode to "Static"

Sinaesthetic
  • 11,426
  • 28
  • 107
  • 176
  • Like I suggested, run the web page and then view source on it. Verify the id of the control. Your null reference error suggests that the control is not named "imgUpload" – Sinaesthetic Jul 26 '12 at 15:22
  • While you're at it, step through it in debug and try to find out exactly what line of code is throwing the exception. For instance, is it a get? a set? Show us the code that caused the error. – Sinaesthetic Jul 26 '12 at 15:28
  • Dear Sinaesthetic! I am a new bee and unable to do exactly what you said. Could you give me your E-mail ID,so that i can send you the solution of my Excercise project pages that are cuasing errors. I will be very greatfull to you, If you help me out here. Thank You – Ravindra Kumar Jul 27 '12 at 08:13
  • Dear Sinaesthetic! thank you ! I just follow your suggestion and i find the mistake that i was doing,now i put the renderd ID of that control in my Javascript function, it`s started working. Thank you Again. – Ravindra Kumar Aug 01 '12 at 11:56