Question

I have two pages default.aspx which has a grdiview. This gridview has two columns one is the Id number and the other the hyperlink of the path of the videos saved in a folder.
I have another page videos.aspx, which accepts a mp4url string to play the videos from the hyperlink clicked on the default page. Now how do I send this url of the hyperlink clicked to this videos page?

default.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        LoadData();
    }
}

//load data from database into gridview
 private void LoadData()
 {
     //code to load the data here
 }
 protected void btnUpload_Click(object sender, EventArgs e)
 {
      //code to upload video here. 
      //Store file details into database if upload successful
      if (blSucces)
      {
          Updatefileinfo(filename, FilePath + filename);
      }
 }
  // I want to send the strpath which is (FilePath + filename) to videos.aspx
  private void Updatefileinfo(string strfilename, string strPath)
  { 
     //code here
  }

Here is the template field of gridview

<asp:TemplateField HeaderText="List of Files" HeaderStyle-Width="50%">
     <ItemTemplate>
        <asp:HyperLink ID="HyperLink1" Target="_blank" runat="server" 
             Text='<%# Eval("filenameName") %>'
        </asp:HyperLink>
     </ItemTemplate>
</asp:TemplateField>

What I want to do is add videos.aspx first to the navigateurl field in the beginning (perhaps I could use string.format, but then how do I recieve that in videos.aspx)

And in the videos.aspx I should recieve only the strPath

protected void Page_Load(object sender, EventArgs e)
{
    VideoPlayer1.Mp4Url = //file path here
}

Any help is appreciated.

Was it helpful?

Solution 2

<asp:HyperLink ID="HyperLink1" Target="_blank" runat="server" 
         Text='<%# Eval("filenameName") %>' NavigateUrl='<%#String.Format("~/videos.aspx?videoPath={0}", Eval("VideoPath"))%>'>
</asp:HyperLink>

and in videos.aspx

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

OTHER TIPS

You can use query string to pass the information from one page to another.

<asp:TemplateField HeaderText="List of Files" HeaderStyle-Width="50%">
     <ItemTemplate>
        <asp:HyperLink ID="HyperLink1" Target="_blank" runat="server" 
             Text='<%# Eval("filenameName") %>' NavigateUrl='<%# "video.aspx?v=" + Eval("VideoPath").ToString() %>'
        </asp:HyperLink>
     </ItemTemplate>
</asp:TemplateField>

and on video.aspx in page load access the video url as below

var vPath = Request.QueryString["v"];
VideoPlayer1.Mp4Url = vPath;

Instead of this

 <asp:HyperLink ID="HyperLink1" Target="_blank" runat="server" 
         Text='<%# Eval("filenameName") %>'
    </asp:HyperLink>

you can use

<a href="videos.aspx?fname=<%#  Eval("filenameName")%>" target="_blank"><%# Eval("filenameName")%></a>

and in videos.aspx.cs file use this

String fname=Request.QueryString["fname"].toString();
VideoPlayer1.Mp4Url =fname;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top