0

I am trying to check my path using script manager and my code is in App_Code here is my code:

public ReportDocument ReportCon(string path)
    {
        ReportDocument cryRpt = new ReportDocument();
        ConnectionInfo info = new ConnectionInfo();
        TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
        Tables CrTables;

        info.ServerName = "192.168.1.200";
        info.DatabaseName = "Track4L";
        info.UserID = "Developers";
        info.Password = "dev01@pps";
        ScriptManager.RegisterStartupScript(this, typeof(Page), "test", "alert('" + path + "');", true);
        cryRpt.Load(path);

        CrTables = cryRpt.Database.Tables;
        foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
        {
            crtableLogoninfo = CrTable.LogOnInfo;
            crtableLogoninfo.ConnectionInfo = info;
            CrTable.ApplyLogOnInfo(crtableLogoninfo);
        }
        return cryRpt;
    }

but i get following error:

 Error The best overloaded method match for 'System.Web.UI.ScriptManager.RegisterStartupScript(System.Web.UI.Page, System.Type, string, string, bool)' has some invalid arguments   D:\DMS\DocumentManagement\Track4L\App_Code\ReportConnection.cs  27  13  D:\...\Track4L\

I don't know how this problem will be solved

Keren Caelen
  • 1,466
  • 3
  • 17
  • 38
Rania Umair
  • 1,965
  • 3
  • 18
  • 18
  • Just a guess, but since you said the above code is in your App_Code folder, I'm betting `this` does not refer to a `System.Web.UI.Page`. – Tim Apr 19 '12 at 05:03
  • @Tim then what i have to do dear – Rania Umair Apr 19 '12 at 05:14
  • Do what @Adil recommended. You'll need to update all the places in your code where `ReportCon` is called to take a `Page` argument and the path argument. – Tim Apr 19 '12 at 05:15

1 Answers1

3

I think you are passing first argument of this method the object of your class. Pass it the object of calling page. I hope your problem will be solved.

    public ReportDocument ReportCon(System.Web.UI.Page myPage, string path)
    {
       // your code
       ScriptManager.RegisterStartupScript(myPage, typeof(Page), "test", "alert('" + path + "');", true);

    }
Adil
  • 146,340
  • 25
  • 209
  • 204
  • Dear but it is not a page it is a .cs file which is prestent in App_Code. what i have to do tell me solution – Rania Umair Apr 19 '12 at 05:07
  • You would be calling this method from your page? If yes then pass your page object in this method like ReportDocument ReportCon(this, "your desired path") – Adil Apr 19 '12 at 05:09
  • But am calling this function in many other pages and they are taking just one argument that is "path" what about them – Rania Umair Apr 19 '12 at 05:11
  • Did you make calls from other pages without ensuring that it is working? Try this it may work Page.ClientScript.RegisterStartupScript(typeof(Page), "OnLoad", "alert('OK');",true ); – Adil Apr 19 '12 at 05:16
  • i get Error An object reference is required for the nonstatic field, method, or property 'System.Web.UI.Page.ClientScript.get' D:\DMS\DocumentManagement\Track4L\App_Code\ReportConnection.cs 27 13 D:\...\Track4L\ – Rania Umair Apr 19 '12 at 05:25
  • what solution you followed passed page object? – Adil Apr 19 '12 at 05:28
  • Try first one pass page object if it works you have to just change your call which is not a big deal i guess – Adil Apr 19 '12 at 05:31