Thumbnails Displaying

53 views Asked by At

I am trying to retrieve thumbnails stored in folder and on clicking the new page will open to run video. Here is the code

<asp:DataList ID="DataList2" runat="server" 
        AutoGenerateColumns="false"
        CellSpacing="5" 
        RepeatColumns="3" 
        Visible="true">
    <ItemTemplate>
        <u><%# Eval("videoTitle") %></u>
        <hr />
        <asp:ImageButton ID="ImageButton1" runat="server" 
                ImageUrl='<%# Eval("thumbPath") %>'
                Height="200" 
                Width="200" 
                href='<%# Eval("videoId", "PlayVideo.aspx?videoId={0}") %>' />
    </ItemTemplate>
</asp:DataList>

On the code behind on page load

public void BindGrid()
{
    string strConnString = ConfigurationManager.ConnectionStrings["Dbconnection"].ToString();
    using (SqlConnection con = new SqlConnection(strConnString))
    {
        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.CommandText = "select videoId, videoTitle,thumbPath from videoUpload";
            cmd.Connection = con;
            con.Open();
            DataList1.DataSource = cmd.ExecuteReader();
            DataList1.DataBind();
            con.Close();
        }
    }
}

I am facing two issues

  1. The image is not displaying on ImageButton(or Image control)
  2. on clicking the imagebutton an error is giving which is given below-

Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page.
For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.

1

There are 1 answers

1
codeandcloud On

The image is not displaying on ImageButton(or Image control)

Its because your thumbpath is wrong.

on clicking the imagebutton an error is giving which is given below

Not getting into EnableEventValidation in this answer because ImageButton is not the Control to use here. Change it to

<asp:HyperLink runat="server"
        NavigateUrl='<%# Eval("videoId", "PlayVideo.aspx?videoId={0}") %>'>
    <asp:Image ID="Image1" runat="server"
        ImageUrl='<%# Eval("thumbPath") %>'
        Height="200"
        Width="200" />
</asp:HyperLink>

On an unrelated side-note, do not use u tag. Its deprecated.