开发者

Putting string from resource between single quotes

开发者 https://www.devze.com 2023-03-07 13:31 出处:网络
I have <asp:TextBox runat=\"server\" ID=\"TextBox1\" value=\"<%$ Resources: WebResource, Se开发者_如何学Pythonarch %>\" onblur=\"if(this.value==\'\') this.value=\'Search\';\" onfocus=\"if(th

I have

<asp:TextBox runat="server" ID="TextBox1" value="<%$ Resources: WebResource, Se开发者_如何学Pythonarch %>" onblur="if(this.value=='') this.value='Search';" onfocus="if(this.value=='Search') this.value='';" />

How can I do something like this for 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='';" />

to localize JavaScript inline?


You could use databinding expressions (<%# %>):

<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) %>'
/>

Make sure you call DataBind on the page. Or in the code behind:

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号