Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a list on design side
XML
<ul id="banner" runat="server" class="bxslider">

</ul>

In code behind I have a webmethod which is called using ajax. When I try to assign value in the above list using its id it gives error which says an object reference is required and when i try to assign value by making an object of the class it says Object reference not set to an instance of an object. Below is the webmethod code:
C#
[WebMethod]
    public static void bind_Banner(string day, string month)
    {
        try
        {
            
            string list = "<li><img src='images/birthday.jpg' width='310px' height='297px'/></li>";
            int width = 310, height = 297;
            
            string str = "select logo,companyname from logos where status='True' AND type='Birthdays' AND day='"+day+"' AND month='"+month+"'";
            DataSet ds = Class1.myTable(str);
            if (ds.Tables[0].Rows.Count > 0)
            {
                list = "";
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    
                    string image = ds.Tables[0].Rows[i][0].ToString().Substring(2);
                    string name = ds.Tables[0].Rows[i][1].ToString();
                    list += "<li><img src='" + image + "' width=" + width + " height=" + height + "/><p class='caption'>" + name + "</p></li>";
                }
            }
            
            _Default obj = new _Default();
            obj.banner.InnerHtml = list; //object reference not set to an instance of an object
            
        }
        catch (Exception ex)
        {

        }


How can I assign value to this list?? Any help would be greatly appreciated.
Thanks
Posted
Updated 28-Jun-13 8:25am
v2
Comments
Asp_Learner 28-Jun-13 11:25am    
Have you tried to popup onfail attribute of Aajx ,try to do that ,you will get idea where you have mistaken ,or use Google Chrome debugger ,by pressing F12 key .
Sergey Alexandrovich Kryukov 28-Jun-13 17:15pm    
Of course, this is how non-static (instance) methods work. So, why would you need static?
—SA
lucky050 28-Jun-13 17:26pm    
I am using a javascript function to call this web method. Below is the code of my js function:
<script type="text/javascript">
function time() {
var currentTime = new Date();
var day = currentTime.getDate();
var month = currentTime.getMonth() + 1;
PageMethods.bind_Banner(day, month);
}
</script>
Sergey Alexandrovich Kryukov 28-Jun-13 17:40pm    
OK, you are not answering my question, so you cannot expect an advice, but you should know that simulation is the input is the UI abuse. It should be used only in some special cases: playing keyboard/mouse macro, software testing tools and the like.
—SA

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