views:

58

answers:

3

I have written a code

function validate()
 {
 if(document.getElementById("<%=txtSearch.ClientID %>").value=="")
 {
  message="Enter the User Id To Search";
  document.getElementById("<%=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?

+5  A: 

They don't.

The server fills them in before sending the JS file to the client.

David Dorward
David is correct. Take a look at the javascript file that your browser loads and you will notice the <%...%> have been replaced.
ScottS
SO that means we get them converted before rendering.
Nadeem
The term "rendering" can be used to mean "the browser generating the graphical representation of the page" (in which case, 'yes, but that happens after the sending of the data I mentioned in the answer') or "the server side program generating the data to send to the client" (in which case, 'no, it happens during that process').
David Dorward
A: 

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.

Christian Nesmark
A: 

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;
 }
Ramakrishnan