How does server tags work in javascript?
I have written a code
function validate()
{
if(document.getElementById("<%=txtSearch.ClientID %>").value=="")
{
message="Enter the User Id To Search";
document.getElement开发者_开发百科ById("<%=lblMessage.ClientID %>").innerHTML=message;
return false;
}
Here I am using <%= %>
tags. I want to know how do they work without making a trip to the server?
They don't.
The server fills them in before sending the JS file to the client.
This would be processed by the ASP.NET engine before the page is sent to the client. It is impossible to include server tags to be processed client-side.
ASP.NET Engine did every thing for you. Web browser can only understand Html mark up, So ASP.NET Engine can convert server side controls as html control in runtime and render it as page.
<%= %>
This is used to access the server side code, or variables like this <%=txtSearch.ClientID %>
You put debugger in javascript code, and analyse it , you can not see this <%=txtSearch.ClientID %>
instead you can see the client id of your server control.
function validate()
{
debugger;
// analyse your seach textbox id, you can not see this `<%=txtSearch.ClientID %>`
if(document.getElementById("<%=txtSearch.ClientID %>").value=="")
{
message="Enter the User Id To Search";
document.getElementById("<%=lblMessage.ClientID %>").innerHTML=message;
return false;
}
精彩评论