开发者

Putting string from resource between single quotes

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜