1

best to show this by code example:

html

<div runat="server" id="PI"> </div> 

c#

protected void addNewProject_Click(object sender, EventArgs e)
{
    PI.attributes.add("z-index", "0");  
}

basically gives me an error saying "the name PI does not exist int he current context."

Any idea why it says that?

Babak Naffas
  • 12,395
  • 3
  • 34
  • 49
Darryl Lobo
  • 155
  • 3
  • 18

3 Answers3

1

Make sure that your .designer.* file has been updated with a variable for PI. Some source control systems lock the file and prevent Visual Studio from automatically updating the file.

If the variable hasn't been created for you, you can always go back to your .designer file and add the new variable yourself. Just follow the patter for your other ASP.NET controls.

You're looking for a partial class with the same name as your code behind class.

This SO question addresses your issue as well.

Community
  • 1
  • 1
Babak Naffas
  • 12,395
  • 3
  • 34
  • 49
1

I found an alternative solution, instead of making the image switch z-indexes, I am making the asp.net panel switch z-indexes. For some reason when I try to declare my object in designer.cs file...it registers in code behind. This is good, however right when I test it out on a web-browser, the designer file auto-regenerates and gets rid of it again. So instead of playing around with the html controls I played around with what I know works and used the asp.net panel controls.

Darryl Lobo
  • 155
  • 3
  • 18
0

I always declare them in my codebehind file, something like this:

var myDiv = new HtmlGenericControl("div");

Then you just treat it the same as any other control on your page.

briskovich
  • 670
  • 1
  • 11
  • 26