在asp.net中查询字符串和自定义控件 [英] Query String and Custom Controls in asp.net

查看:61
本文介绍了在asp.net中查询字符串和自定义控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开设一个网站,允许用户将视频上传到我的网站。我想动态显示上传的视频,即每当用户上传视频时视频都应该可见。为此,我建立了一个自定义控制视频播放器。如果我直接提供mp4url,它工作正常。但是,如果我使用查询字符串传递mp4url,它就无法工作。



我有一个提交页面,允许用户使用文件上传控件上传视频,这些是上传到上传文件夹



I am working on a website which allows users to upload videos to my site. I want to display the uploaded videos dynamically i.e. 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. However, if I pass the mp4url using querystring, it is not working.

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);
    }



有一个名为Videos的页面有一个视频播放器,它使用查询字符串接收Mp4Url




There is a page called "Videos" which has a video player, it receives "Mp4Url" using the querystring

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





这是行不通的,知道哪些更改会纠正这个问题?(问题是视频播放器没有播放视频)



PS



This is not working, any idea of what changes will rectify this issue?(Issue is the video player is not playing the video)

P.S.

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" />



工作正常。但是,这需要手动分配mp4url。


it's working fine. However, that requires manual allocation of the mp4url.

推荐答案

这对我来说看起来没有用,试图从查询字符串中分配url。



您使用以下行重定向到Videos.aspx:



This does not look valid to me, trying to assign the url from the query string.

You redirect to "Videos.aspx" using this line:

Response.Redirect("Videos.aspx?VideoURL=" + ((ImageButton)sender).ImageUrl);





Page_Load (或根据您的需要使用合适的页面方法)Videos.aspx,您可以查看查询字符串并将其分配给自定义控件吗?





In the Page_Load (or the suitable page method as per your need) of "Videos.aspx", you can check the query string and assign it to the custom control?

protected void Page_Load(object sender, EventArgs e)
{
   var url = Request.QueryString["VideoURL"];
   
   if (!string.IsNullOrEmpty(url))
   {
       VideoPlayer1.Mp4Url = url;
   }
}





<%#..%>格式应该用于数据绑定,这不是数据绑定的合适案例。例如,您可以在网格视图中使用它将属性的值绑定到网格视图列。



The <%# .. %> format should be used for "data-binding" and this is not a suitable case for data binding. For example, you could use this in a grid view to bind the value of a property to a grid view column.


我设法纠正了代码。导致问题的是〜/

I managed to correct the code. It was the "~/" which was causing the problem
imageButton.ImageUrl = "Uploads/" + fi.Name;



上述更改使其有效!


The above change made it work!


这篇关于在asp.net中查询字符串和自定义控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆