I’ve been looking about and cant figure out how to get a value from C# into the tag on an ASPX page. I’ve tried a number of options but not getting anywhere.
When my asp page loads, a value is obtained using queryString from the pages url (i.e. mypage.aspx?app=safety )
It then runs a switch to find out what image url to use on the page.
Thing is, I get a Compilation Error “The name ‘img_small’ does not exist in the current context”. What do you think of my code below? I cant see what Im missing!
C#:
protected void Page_Load(object sender, EventArgs e)
{
string img_small;
String appName = Request.QueryString["app"];
switch (appName)
{
case "safety":
img_small = "safety-logo.png";
break;
case "files":
img_small = "files-logo.png";
break;
case "drawings":
img_small = "drawings-logo.png";
break;
case "specs":
img_small = "specs-logo.png";
break;
default:
img_small = "idms-logo.png";
break;
}
}
HTML:
<img src='"<%=img_small%>"' />
This is because
img_smallis a local variable ofPage_Loadfunction, it doesn’t exist outside this function. This is why you get this error.I’d suggested you to change
to
And then at the bottom of
Page_Loadfunction do