locked
Passing values from aspx.cs to .aspx RRS feed

  • Question

  • I've a website hosted in a server in my network and I'm accessing it from my local machine.

    The aspx.cs file has all the codes/functions. The values are collected from the webpage.

    I need to pass these values from the function in aspx.cs file to the .aspx file where I have a script running.

    How do I do it?

    Friday, July 17, 2015 12:04 PM

Answers

  • Hello,

    To pass values from .aspx.cs to the .aspx, a simple solution is to use the <%= %> syntax, for example:

    the .aspx.cs file:

    public partial class Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                MyProperty = "My property value";
            }
    
            public string MyProperty { get; set; }
    
            public string MyMethod()
            {
                return "Hello World";
            }
        }

    the .aspx file:

        <div>
            <%=MyProperty %><br />
            <%=MyMethod() %>
        </div>

    By the way, this forum is for questions about JScript.Net, please post ASP.NET questions in ASP.NET forums here:

    http://forums.asp.net/


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Sunday, July 19, 2015 11:06 AM
    Moderator

All replies

  • Hello,

    To pass values from .aspx.cs to the .aspx, a simple solution is to use the <%= %> syntax, for example:

    the .aspx.cs file:

    public partial class Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                MyProperty = "My property value";
            }
    
            public string MyProperty { get; set; }
    
            public string MyMethod()
            {
                return "Hello World";
            }
        }

    the .aspx file:

        <div>
            <%=MyProperty %><br />
            <%=MyMethod() %>
        </div>

    By the way, this forum is for questions about JScript.Net, please post ASP.NET questions in ASP.NET forums here:

    http://forums.asp.net/


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Sunday, July 19, 2015 11:06 AM
    Moderator
  • Thank you Caillen, for the helpful response.

    Good Day!

    Saturday, August 1, 2015 6:57 PM