从Windows窗体应用程序转换asp .net幻灯片

时间:2017-08-10 12:14:41

标签: c# asp.net

我对asp .net没有任何了解,我想要做的是将我创建的Windows窗体应用程序转换为asp。应用程序几乎是一个从文件夹和节目中拍照的滑块他们每隔5秒就在屏幕上播放一次。我在asp net中尝试了这段代码:

List<string> keliai = new List<string>();
int sk = 0;
protected void Timer1_Tick(object sender, EventArgs e)
        {
            Timer1.Interval = 5000;
            timmeh();
        }

public void timmeh()
        {
            string path = @".";

            string[] filePaths = Directory.GetFiles(path, "*.jpg");
            string[] filePathsPng = Directory.GetFiles(path, "*.png");


            for (int i = 0; i < filePaths.Length; i++)
            {
                keliai.Add(filePaths[i]);
            }


            if (sk < keliai.Count)
            {
                picB.ImageUrl=keliai[sk];
                sk++;
            }
            else
            {
                sk = 0;
            }
        }

而不是picB.ImageUrl=keliai[sk];我使用picB.Image = new Bitmap(keliai[sk]); in forms. 当我启动项目时,我得到一个例外

[InvalidOperationException: The control with ID 'Timer1' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.]
   System.Web.UI.Timer.get_ScriptManager() +190
   System.Web.UI.Timer.OnPreRender(EventArgs e) +22
   System.Web.UI.Control.PreRenderRecursiveInternal() +88
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +883

我应该如何更改代码,以便程序也适用于asp .net?

1 个答案:

答案 0 :(得分:1)

从页面上的工具箱中拖放控件ScriptManager。您在我们的页面中使用的任何ajax控件都需要ScriptManager

您的表单的HTML可能如下:

<body>
    <form runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        ...
     <!--Here you might have the timer control-->
    </form>
</body>

您可以使用许多免费的jQuery插件来获得更好的体验。可能是这样的: http://bxslider.com/examples/image-slideshow-captions