tags:

views:

368

answers:

6

I have an input control on a page like this:

<input 
    type="button" 
    causesvalidation="false"
    runat="server" 
    id="resetButton"  
    value="Iptal" 
    onclick='return  
    resetForm("<%=projectValidationSummary.ClientID%>");' />

when it is rendered

<input 
    name="ctl00$ContentPlaceHolder1$EditForm$resetButton" 
    type="button" 
    id="ctl00_ContentPlaceHolder1_EditForm_resetButton" 
    value="Iptal" 
    onclick="return  resetForm(&quot;&lt;%=projectValidationSummary.ClientID%>&quot;);" />

I use <%=%> tags on page but it is rendered as

&quot;&lt;%=%>&quot;

Can anyone tell my why this is happening?

+1  A: 

Because there is an HTML encoding taking place for the string in resetForm.

User
A: 

This may be obvious, but did you ensure that the file type is appropriate? I.e. jsp for a JSP or asp for an ASP?

This should be getting caught by the compiler before encoding. Is it possible that there is pre-processing before compiling the page? Your id is changed and it added a name element...

Jesse
+2  A: 

You can't mix and match render blocks with text for values. Try this

onclick='<%= "return resetForm(\"" + projectValidationSummary.ClientID + "\");" %>'
Bob
+2  A: 

Remove the runat="server" - you don't need it if you're doing a literal write (<%=)

So:

<input 
  type="button" 
  causesvalidation="false"
  id="resetButton"  
  value="Iptal" 
  onclick="return resetForm('<%= projectValidationSummary.ClientID %>');" />

Or use a databind instead:

<input 
  type="button" 
  causesvalidation="false"
  id="resetButton"  
  runat="server"
  value="Iptal" 
  onclientclick="return resetForm('<%# projectValidationSummary.ClientID %>');" />

//in code behind:
resetButton.DataBind();

.Net doesn't like literal writes inside server rendered controls other than panels.

Keith
In the second code area the onlick is a server event and 'return resetForm...' is there for not a valid assignment.
bang
Well spotted - I've changed it to onclientclick
Keith
+2  A: 

Since you're already using runat="server" you're better off setting this property in the code-behind anyway.

resetButton.attributes.add("onclick", ".....");

ScottE
+2  A: 

<%= %> is only usable inside literal html and can't be used on a server controls attribute.

Instead you should us databinding <%# %>, and in your case i think you are trying to trigger a javascript function on your client side and then your code should look like this:

<asp:button
causesvalidation="false"
runat="server"
id="resetButton"
text="Iptal"
onclientclick='<%# String.Format("return resetForm(\"{0}\");", projectValidationSummary.ClientID) %>' />

and on the server side you should bind the attribute with this code (probably in the Page.Load event):

if(!this.IsPostBack)
{
  this.resetButton.DataBind();
}
bang
thnx for our helpsi made js function "resetForm" non parameter and i got item's clientId inside javascript function in this case...
dankyy1