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);
精彩评论