Bikram
Bikram

Reputation: 197

How can we use 'if...else' in asp.net on front-end

I want to use front-end code in an asp.net 4.0v form. Here is the code:

<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
if(Request.Params["store"].ToString() == "Store")
{
<video src='<%# "VideoHandler.ashx?id=" + Eval("id") %>' 
width="900" height="400" controls="" preload=""></video>
}
else if (Request.Params["video"].ToString() == "Videos")
{
<video src='<%# "Handler.ashx?id=" + Eval("id") %>' 
width="900" height="400" controls="" preload=""></video>
}
</ItemTemplate>
</asp:Repeater>

I want to play video as a condition of query string. How can I do this in front-end code? Please help me with it.

Thank you

Upvotes: 1

Views: 2870

Answers (2)

Umar Sid
Umar Sid

Reputation: 1337

I think you should use a function in code behind page which takes the query string as parameter and return your desired string i.e Handler.aspx or VideoHandler.aspx

code :

<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>

<video src='<%# "Handler.ashx?id=" + Eval("id") %>'  width="900" height="400" controls="" preload=""></video>

</ItemTemplate>
</asp:Repeater>

Now Write a function on the code behind page

protected string myFunction(String id)
{
if (Request.Params["store"].ToString() == "Store")
{
    return ("VideoHandler.ashx?id=" + id)
}else if(Request.Params["store"].ToString() == "Videos")
{
  return ("Handler.ashx?id=" + id)
}

}

Upvotes: 1

trnelson
trnelson

Reputation: 2763

You could use the parameter as follows:

<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>

<video src='<%# GetVideoHandler(Eval("id")) %>' 
width="900" height="400" controls="" preload=""></video>


</ItemTemplate>
</asp:Repeater>

And then have a function to handle the conditional:

protected string GetVideoHandler(int videoId)
{
    if (....)
    {
        // Code here
    }
}

Upvotes: 1

Related Questions