简体   繁体   English

在ASP.NET中查询字符串和自定义控件

[英]Query String and Custom Controls in asp.net

I am working on a website which allows users to upload videos to my site. 我正在一个允许用户将视频上传到我的网站的网站上。 I want to display the uploaded videos dynamically ie the videos should be visible whenever an user uploads a video. 我想动态显示上传的视频,即无论何时用户上传视频,视频都应该可见。 To do this I have a custom control video player built. 为此,我构建了一个自定义控件视频播放器。 It works fine if I provide the "mp4url" directly. 如果我直接提供“ mp4url”,效果很好。 However, if I pass the mp4url using querystring, it is not working. 但是,如果我使用querystring传递mp4url,则无法正常工作。

I have a submit page which allows users to upload videos using a fileupload control, and these are uploaded to "Uploads" folder 我有一个提交页面,该页面允许用户使用文件上传控件上传视频,并将这些视频上传到“上传”文件夹中

 //Move through the "Uploads" folder and display the thumbnails of the videos after file has been uploaded
    private void LoadThumbnails()
    {
        foreach (string strfile in Directory.GetFiles(Server.MapPath("~/Uploads")))
        {
            ImageButton imageButton = new ImageButton();
            FileInfo fi = new FileInfo(strfile);
            imageButton.ImageUrl = "~/Uploads/" + fi.Name;
            imageButton.Height = Unit.Pixel(100);
            imageButton.Style.Add("padding", "5px");
            imageButton.Width = Unit.Pixel(100);
            imageButton.Click += new ImageClickEventHandler(imageButton_Click);
            Panel1.Controls.Add(imageButton);
        }
    }

    //Redirect to the "Videos" page using Querystring
    protected void imageButton_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("Videos.aspx?VideoURL=" + ((ImageButton)sender).ImageUrl);
    }

There is a page called "Videos" which has a video player, it receives "Mp4Url" using the querystring 有一个名为“ Videos”的页面,该页面具有视频播放器,它使用查询字符串接收“ Mp4Url”

 <cc1:VideoPlayer ID="VideoPlayer1" runat="server" Mp4Url='<%# Request.QueryString["VideoURL"]%>'  Width="400" Height="300" />

This is not working, any idea of what changes will rectify this issue?(Issue is the video player is not playing the video) 这是行不通的,任何想法都可以解决此问题?(视频播放器未在播放视频)

PS 聚苯乙烯

      protected void Page_Load(object sender, EventArgs e)
      {
        VideoPlayer1.Mp4Url = Request.QueryString["VideoURL"];
      }

Even the above code in the code behind file for the Videos page is not working. 甚至“视频”页面的文件背后代码中的上述代码也不起作用。

If i use 如果我用

<cc1:VideoPlayer ID="VideoPlayer1" runat="server" Mp4Url="Uploads/movie.mp4"  Width="400" Height="300" />

it's working fine. 工作正常。 However, that requires manual allocation of the mp4url. 但是,这需要手动分配mp4url。

Okay, I learnt that the ~/ is not always useful :) The reason this was not working was 好的,我了解到〜/并不总是有用的:)这不起作用的原因是

imageButton.ImageUrl = "~/Uploads/" + fi.Name;

I removed the ~/ from the above line and it started to work like a charm :) 我从上面的行中删除了〜/,它开始工作就像一个魅力:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM