GabrielVa
GabrielVa

Reputation: 2388

C# Image and label issue

I have an issue when I'm trying to make my image or label visible in my web app.

using System;
using System.Linq;
using System.Web.Security;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Services;
using System.IO;
using System.Web.UI.Adapters;


public partial class Admin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }


protected void Timer1_Tick(object sender, EventArgs e)
    {
        if (File.Exists("c:/test.pdf"))
            //inform user
            Console.WriteLine("File uploaded.");
        Image1.visible = true; 

I'm getting an error as follows:

The name 'Image1' does not exist in the current context

Any ideas here? Ive done this before without issue, but for some reason it doesn't like the image1 (which i put on my webpage and made visible = false) nor the label which is also visible = false.

Upvotes: 0

Views: 906

Answers (4)

DavideDM
DavideDM

Reputation: 1495

I think the problem is that timer_tick it's not in the same thread of your web app

Upvotes: 0

NakedBrunch
NakedBrunch

Reputation: 49423

Try deleting the designer.cs file for the page and then re-open the aspx page in Design mode. Next do a full rebuild of the project and try again.

Upvotes: 0

Will Charczuk
Will Charczuk

Reputation: 919

Make sure that Image1 is declared "protected", also make sure that Image1 is the id="" for the runat="sever" control on the page.

If neither of these work, try making a trivial change to the markup to recompile the whole page class.

Upvotes: 1

Somedeveloper
Somedeveloper

Reputation: 867

had issues similar to this before, usually caused by the designer not updating after adding new control to the page. to fix i would recommend

  1. taking the image control with id of image1 out of the page.
  2. then save the page.
  3. now close the aspx page.
  4. re open the aspx again
  5. place image control with id image1 back onto the page again and save.

think it should work now.

Upvotes: 0

Related Questions