Need help with ajax...

Hi,

I'm getting a red underline warning from Intellisense saying "An object reference is required for
the non-static field, method, or property '_Default.slideShowContainer'  for the line "slideShowContainer.Visible = false;" below. All I need to do is hide the div container "slideShowContainer" when GetSlides() returns a null.

Can someone tell me how to solve this?

Thanks very much in advance.
<asp:ScriptManager ID="ScriptManager1" runat="server" />
    
    <script runat="Server" type="text/C#">    
    [System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public static AjaxControlToolkit.Slide[] GetSlides()
    {
        try
        {
            HttpContext context = HttpContext.Current;
            string xlsPath = context.Server.MapPath("~/uploadedFiles/slideshow.xls");
            if (File.Exists(xlsPath))
            {
                string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + xlsPath + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'";
 
                DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
 
                List<AjaxControlToolkit.Slide> slides = new List<AjaxControlToolkit.Slide>();
 
                using (DbConnection connection = factory.CreateConnection())
                {
                    connection.ConnectionString = connectionString;
 
                    using (DbCommand command = connection.CreateCommand())
                    {
                        command.CommandText = "SELECT ImageFile, ImageTitle, ImageDesc FROM [Slides$] s WHERE LEN(LTRIM(RTRIM(ImageFile))) >= 5 AND LEN(LTRIM(RTRIM(ImageDesc))) > 0 ORDER BY ImageFile";
                        connection.Open();
                        using (DbDataReader dr = command.ExecuteReader())
                        {
                            while (dr.Read())
                            {
                                slides.Add(new AjaxControlToolkit.Slide("uploadedimages/" + dr["ImageFile"].ToString().Trim(), dr["ImageTitle"].ToString().Trim(), dr["ImageDesc"].ToString().Trim()));
                            }
                        }
                    }
                }
                return slides.ToArray();
            }
            return null;
            slideShowContainer.Visible = false;
        }
 
        catch (Exception ex)
        {
            throw ex;
        }
    }
    </script>
    
    <div id="slideShowContainer" runat="server">
    <table id="slideShow" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td>
                <asp:Image ID="imgSlide" runat="server" ImageUrl="images/slide_Image1.jpg" />
        
                <sc1:SlideShowExtender ID="SlideShowExtender1"
                  AutoPlay="true" ImageDescriptionLabelID="lblImageDescription"
                   Loop="true" NextButtonID="btnNext" PlayButtonID="btnPlay" 
                    PlayButtonText="Play" PreviousButtonID="btnPrevious" 
                    SlideShowServiceMethod="GetSlides" StopButtonText="Stop" 
                    TargetControlID="imgSlide" runat="server">
                </sc1:SlideShowExtender>
            </td>
        </tr>
        <tr>
            <td id="slideShowButtons">
                <asp:ImageButton ID="btnPrevious" runat="server" ImageUrl="images/back_arrowgraphic.gif" ToolTip="Previous slide" />
                <asp:ImageButton ID="btnPlay" runat="server" ImageUrl="images/pause_arrowgraphic.gif" ToolTip="Pause/Play" />
                <asp:ImageButton ID="btnNext" runat="server" ImageUrl="images/forward_arrowgraphic.gif" ToolTip="Next slide" />
            </td>
        </tr>
        <tr>
            <td id="slideShowText">
                <asp:Label ID="lblImageDescription" runat="server" />
                <br /><br />
            </td>
        </tr>
    </table>
    </div>

Open in new window

WebAppDeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AruspexCommented:
You are trying to access a control that doesnt exist in the context if its a static method, In order to use a non-static field, method, or property, you must first create an object instance.

0
WebAppDeveloperAuthor Commented:
So how do I do that?
0
AruspexCommented:
Hey WebAppDeveloper,

You can try removing the static definition from the method declaration.

ie from
public static AjaxControlToolkit.Slide[] GetSlides()

to

public AjaxControlToolkit.Slide[] GetSlides()

that should fix it.

You will also need to change;
 return null;
slideShowContainer.Visible = false;

to

slideShowContainer.Visible = false;
 return null;

as nothing can execute after a return call (The compiler will warn with unreachable code detected)






0
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

WebAppDeveloperAuthor Commented:
I removed "static" from "public static AjaxControlToolkit.Slide[] GetSlides()" and changed from
"return null;
slideShowContainer.Visible = false;"
to
"slideShowContainer.Visible = false;
 return null;"

But it gave me another error.

Then I put the "static" back and tried the following, and it doesn't work neither, although no complaint from intellisence:
            ........
                return slides.ToArray();
            }
            Page page = (Page)HttpContext.Current.Handler;
            HtmlGenericControl divControl = new HtmlGenericControl();
            divControl = (HtmlGenericControl)page.FindControl("slideShowContainer");
            divControl.Visible = false;
            return null;

Any other advice???

0
AruspexCommented:
Hello,

What error did it give you when you removed the static keyword?

0
WebAppDeveloperAuthor Commented:
The error is:

Microsft JScript runtime error: Sys.Net.WebServiceFailedException: The server method 'GetSlides' failed with the following error: <html>
<head>
<title>Unknown web method GetSlides.<br>Parameter name: methodName</title>
........<h2><i>Unknown web method GetSlides.<br>Parameter name: methodName</i></h2>......
0
AruspexCommented:
Can you put this method into a codebehind file?

What is the purpose of marking it with
[System.Web.Services.WebMethod]

Is it supposed to be a method on a webservice?




0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WebAppDeveloperAuthor Commented:
Aruspex,

Yes, it's supposed to be a method in a webservice. I can put the whole web method into a separate file called "slidesservice.cs" and save it in the App_Code folder and then another file called "slidesservice.asmx" that calls the web method in "slidesservice.cs".
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.