Reputation: 15470
I need help on this following aspx code
aspx Code:
<asp:Label ID ="lblName" runat ="server" Text ="Name"></asp:Label>
<asp:TextBox ID ="txtName" runat ="server"></asp:TextBox>
Consider this is my aspx page content. I am going to populate the values for the TextBox only after the postback from server. But the label is also posting to the server (runat="server"
) even though it's not necessary. Should I write my code like this to save time from server with less load.
Corrected Code:
<label id ="lblNames">Name</label>
<asp:TextBox ID ="txtName" runat ="server"></asp:TextBox>
Only my server control will send to the server for postback and not my HTML control which has a static value.
Please suggest whether this is the correct way of coding.
Upvotes: 0
Views: 435
Reputation: 4156
.net label controls are rendered as html label elements and do not get posted back to the server. Labels just don't post back. The server control allows you to manipulate the properties of the control in code however which is very useful.
There is nothing wrong with using html tags as well in your aspx/ascx page though if you don't need any programmatic control of the element.
Upvotes: 0
Reputation: 416149
If you're not doing anything with the label server-side, then just use a <span>
. It'll end up as the same html at the browser.
Upvotes: 0
Reputation: 100047
If you take the runat='server'
out of the <label>
element then it won't be parsed as a server control. If you're not going to do anything with lblNames
from the server then it is perfectly okay to leave it out.
Upvotes: 3