You can do it with <%= variable %> as well, but it's nicer to do it in code behind.

For a reference on <%-tags, go to http://samples.gotdotnet.com/quickstart/aspplus/doc/webformssyntaxref.aspx

To access properties defined in code-behind inside your HTML part, you would need to define your proeprties or variables as public, and then use them as follows:

<%= this.MyVariable %>

Even though this post is old, it sends out a not-so-good idea that one should use Label/Literal to build the HTML using the variables to achieve this objective. This is not always good because we are loading the server with the job of creating the HTML for you, which could've easily done using the raw HTML itself.

if the requirement is simple, it can be preferred to be done by just using the public variable name <%= this.MyVariable %> as Haidar mentioned above. You can also use any of the approaches mentioned at the below URL to fetch the variable value and use it.

Hi, here is the answer of your query: //1.Assuming you have aspx with two text boxes (txtFirstName & txtLastName)//2.Now, Set properties of your class like below under button click event and pass the object directly to InsertRecords method: