Himanshu Kaushik
Himanshu Kaushik

Reputation: 21

Not able to access a variable from code behind in aspx page

I have declared a variable in code behind the variable name is progressbar which is of int type

to access this variable in the same asp.net page i am using this code

 <table align="center" border="1" cellpadding="0" cellspacing="0" frame="border" 
        style="border-color: #FF0000" width="100%">
    <tr>
        <td bgcolor="#FF0066" colspan="0" rowspan="0" width="<%= progressbar %>%">
            &nbsp;</td>
        <td colspan="0" rowspan="0">
            &nbsp;</td>
    </tr>

i have used both <%= progressbar %> and <%# progressbar %> but not able to access this variable.
Can you tell me how can I access this variable from c# code behind to the asp.net page

Upvotes: 1

Views: 2830

Answers (2)

EJC
EJC

Reputation: 2161

  1. Make sure the variable you're trying to access is not private

  2. You should be able to accesss it like this <%= progressbar %>

within the class write

public int progressbar = 0;

Upvotes: 4

Matti Virkkunen
Matti Virkkunen

Reputation: 65166

All variables in C# are local variables, and they're only visible inside the function they were declared in. Make your thing a field or a property instead, and make sure it's either protected or public.

Upvotes: 2

Related Questions