tags:

views:

350

answers:

4

I have a html file need to refresh every 10 seconds, so I have this line in html :

meta http-equiv="Refresh" content="10; url=Default.aspx"

In my C# code I have this :

public partial class _Default : System.Web.UI.Page<Br>
{
  public static List<String> Active_User_List=
      new List<String>(), User_List_To_Remove;
  public static int Refresh_In_Seconds=10;<Br>
  ..
}

How to replace the 10 with the variable "Refresh_In_Seconds" ?

A: 

Use this:

<meta http-equiv="Refresh" content="<%= Refresh_In_Seconds %>"; url=Default.aspx" />
M4N
+2  A: 

Try:

<meta http-equiv="Refresh" content="<%=Refresh_In_Seconds%>; url=default.aspx" />

FYI, that should probably not be a static member.

Rex M
A: 

Use this:

<meta http-equiv="Refresh" content="<%= _Default.Refresh_In_Seconds %>"; url=Default.aspx" />
Mike Chaliy
+1  A: 

Don't do inline code hacks, do it right:

public partial class _Default : System.Web.UI.Page
{
    private const int _refresh_In_Seconds = 10;

    public override void OnInit(object sender, EventArgs e)
    {
        HtmlMeta meta = new HtmlMeta();
        meta.Name = "refresh";
        meta.Content = _refresh_In_Seconds + "; url=Default.aspx"; 

        this.Header.Controls.Add(meta);
    }
}
FlySwat
How are inline code hacks? Does that mean ASP.NET MVC is one giant hack?
Rex M
He isn't using MVC. On Webforms, inline code is hackish.
FlySwat
Much cleaner than the inline "hacks".
M4N
Not to mention that inline code is not allowed in some situations on webforms.
FlySwat
Hm, why MVC is ok and webForms is not? Common!, inline code is just much more readable...
Mike Chaliy
The important thing is that you're not cutting and pasting it between multiple pages. The method you are using to share functionality between pages determines which answer is best. I just inherit from a custom Page object, so this answer is better for me. If you are using a master page setup, the inline code might be easier.
quillbreaker