Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Hello , first sory my poor english. In my project ı have been trying to display value from code behing but ı get this mesage even ı have checked the variable is null or not

Compiler Error Message: CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
HTML
<br />

                         <div class="prod_price_big"><span class="reduce">350$</span>&lt;%if (Price != null) { %&gt; &lt;% Price;
                                                                                       }%&gt; <span>


and my code behind is
C#
public Users user
      {
          get { return Session["user"] as Users; }
          set { Session["user"] = value; }
      }

      ShipperResposite _shiperResposite = new ShipperResposite();
      decimal Pricee;
      public decimal Price
      {
          get { return Price; }
          set
          {
              value = Pricee;
              Price = value;
          }
      }

      protected void Page_Load(object sender, EventArgs e)
      {
          if (user == null)
              Response.Redirect("~/Default.aspx", true);
          if(Price==null)
              Response.Redirect("~/Default.aspx", true);

          DropDownList1.DataSource = _shiperResposite.ListShippers().ToList();
          DropDownList1.DataTextField = "CompanyName";
          DropDownList1.DataValueField = "ID";
          DropDownList1.DataBind();
          Pricee = _shiperResposite.GetPriceFromID(Convert.ToInt32(Request.QueryString["ID"]));

      }


      }
  }</span></div>
Posted
Updated 1-Jan-13 16:01pm
v3
Comments
Sergey Alexandrovich Kryukov 1-Jan-13 22:00pm    
Can you format the code properly? I added "pre" tags, you will see it if you click "Improve question", but please fix it properly.
—SA
Sergey Alexandrovich Kryukov 1-Jan-13 22:02pm    
In what line do you have this error?
—SA
Christian Graus 1-Jan-13 23:14pm    
Isn't it obvious ?

Your code translates to this :
C#
if (Price != null) { %><% Price; }


Price is a variable, and you're using it as an expression. I would suggest making Price a property that never returns null, and replacing all of this with =Price. The alternative is to replace Price with Response.Write(Price), Price by itself is not a statement to output that variable, and it has no value, and creates the error ( which is NOT a null reference, that's why it doesn't say 'null' anywhere ).

The two code blocks are also messing you up. Get rid of the middle ones, the ones I quoted.
 
Share this answer
 
CSS
}

    ı have revize my code like this 

 public decimal Price
        {
            get { return Price; }
            set
            {
                Price=_shiperResposite.GetPriceFromID(Convert.ToInt32(Request.QueryString["ID"]));
                Price = value;
            }
        }



 

and ı have changed my code like this at html side

 <div class="prod_price_big">350$<![CDATA[<%=Price %>]]> </div>

this code block give me this eror mesage "An unhandled exception of type 'System.StackOverflowException' occurred in WebApplication34.dll" 
ı think it is about wrong using of my property ı created o method which  give me a variable which ı need . I can see this variable in debug mode but ı could not trensfer it to html side. Sory for my poor knowledge ı am new at programing thanks for helps
 
Share this answer
 
Comments
Abhishek Pant 2-Jan-13 21:07pm    
Please update that in your question above and delete this.Next time remember that not to post your comments as answers
You can used like classic asp


1
C#
<%
if (Price != null) { Response.write(Price); }
%>


and
2.

C#
<%
if (Price != null) {%> <%=Price%><% }
%>

3.

C#
<%=((Price != null)?Price:0)%>



I hope your problem will solve if not please give your comments
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900