2011-05-23 98 views
0

之間我有把字符串從資源單引號

<asp:TextBox runat="server" ID="TextBox1" value="<%$ Resources: WebResource, Search %>" onblur="if(this.value=='') this.value='Search';" onfocus="if(this.value=='Search') this.value='';" /> 

我怎麼可以做這樣的事情了的onblur

<asp:TextBox runat="server" ID="TextBox1" value="<%$ Resources: WebResource, Search %>" onblur="if(this.value=='') this.value='<%=Resources.WebResource.Search %>';" onfocus="if(this.value=='<%=Resources.WebResource.Search %') this.value='';" /> 

本地化的JavaScript內聯?

+0

感謝Darin,我的Google Chrome篩選器出錯了 – johnny 2011-05-23 07:24:49

回答

1

你可以使用數據綁定表達式(<%# %>):

<asp:TextBox 
    runat="server" 
    ID="TextBox1" 
    value="<%$ Resources: WebResource, Search %>" 
    onblur='<%# string.Format("if(this.value==\"\") this.value=\"{0}\"", Resources.WebResource.Search) %>' 
    onfocus='<%# string.Format("if(this.value==\"{0}\") this.value=\"\"", Resources.WebResource.Search) %>' 
/> 

確保您在頁面上調用DataBind。或者在後面的代碼中:

TextBox1.Attributes["onblur"] = string.Format("if(this.value==\"\") this.value=\"{0}\"", Resources.WebResource.Search); 
TextBox1.Attributes["onfocus"] = string.Format("if(this.value==\"{0}\") this.value=\"\"", Resources.WebResource.Search);