user2224493
user2224493

Reputation: 269

How to call a property from ASP.NET web form file

I am trying to populate the value of input field with value from property. How can I do that besides setting in the code behind file?

<%@ Import Namespace="PCF.Entities.Models" %>

<input id="firstName" type="text" value="<%  %>" size="26"  maxlength="15"   name="firstName" tabindex="2" runat="server" disabled="disabled" />

Upvotes: 0

Views: 504

Answers (2)

R P
R P

Reputation: 348

make your input field runat="server" and you will get the access of input at code behind file.

Upvotes: 1

Win
Win

Reputation: 62260

You can use <%= %>

ASPX

<%= Name %>

Code Behind

protected string Name
{
    get { return "John Doe"; }
}

However, in your scenario. You should be using ASP.Net Textbox control.

ASPX

<asp:TextBox runat="server" ID="FirstNameTextBox"
        MaxLength="15" Enabled="False" />

Code Behind

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        FirstNameTextBox.Text = "John Doe";
    }
}

Upvotes: 0

Related Questions