Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I implemented the following code in asp.net

C#
 protected void Page_Load(object sender, EventArgs e)
    {      

        TryToParse(null);
        TryToParse("160519");
        TryToParse("9432.0");
        TryToParse("16,667");
        TryToParse("   -322   ");
        TryToParse("+4302");
        TryToParse("(100);");
        TryToParse("01FA");
    }

private static void TryToParse(string value)
    {
        int number;
        bool result = Int32.TryParse(value, out number);
        if (result)
        {
           Response.Write(value+" "+number);// Intelligence window is not showing the Response property. 
        }
        else
        {
            if (value == null) value = "";
            Response.Write("Attempted conversion of '{0}' failed.", value);
        }
    }


Response.Write is not working in static method..Can u please tell me..
Posted
Comments
bbirajdar 9-Jul-12 6:58am    
Remove the static keyword....

Why is the method marked as static?

Based on what you are doing in it, you should just remove static and keep the method signature as private void.
 
Share this answer
 
Comments
Srinubabu Ravilla 9-Jul-12 7:23am    
Sir, I removed the static and tried it is working fine but my doubt is why the intelligence is not showing the Response object.Why Response object is not working in Static method.
The reason its not working when the method is static is Response is instance object created for every page by asp.net plese refer this link


http://www.dotnetspider.com/tutorials/AspNet-Tutorial-36.aspx[^]


An instance of this class is created by default in all the pages, so that you can use this object without creating again each time in all the pages. The name of this object is Response.

When you are using the static method in the Page class, Page class won't have an instance object associted with it hence the error..
 
Share this answer
 
Comments
bbirajdar 9-Jul-12 8:03am    
Nice answer +5

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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