Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET WebForms C#4.0
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
 
   <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
  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 1-Jan-13 15:52pm
burak88375
Edited 1-Jan-13 16:01pm
v3
Comments
Sergey Alexandrovich Kryukov at 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 at 1-Jan-13 22:02pm
   
In what line do you have this error?
—SA
Christian Graus at 1-Jan-13 23:14pm
   
Isn't it obvious ?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

You can used like classic asp
 

1
<%
if (Price != null) { Response.write(Price); }
%>
 
and
2.
 
<%
if (Price != null) {%> <%=Price%><% }
%>
3.
 
<%=((Price != null)?Price:0)%>
 

I hope your problem will solve if not please give your comments
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Your code translates to this :
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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

}
 
    ı 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"><span class="reduce">350$</span><![CDATA[<%=Price %>]]><span class="price"> </span></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
  Permalink  
Comments
Abhishek Pant at 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

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 598
1 George Jonsson 268
2 OriginalGriff 215
3 CPallini 210
4 PIEBALDconsult 155
0 OriginalGriff 5,835
1 Sergey Alexandrovich Kryukov 5,263
2 CPallini 4,750
3 George Jonsson 3,227
4 Gihan Liyanage 2,487


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 5 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100