Labels

Friday, November 7, 2008

<% %> Magic

Hi,

This blog post summarizes a few approaches of <% %> Magic.

Message Retrieval from Resource Files

var msg = '<%=GetLocalResourceObject("ValidationMsg")%>'

var msg = '<%=GetGlobalResourceObject("PageTitle", "DebtParametersOther")%>';

var msg = '<%=GetGlobalResourceObject("PageTitle", "DebtParametersOther").ToString().EncodeQuotes()%>';

// Code at Server Side

public static string EncodeQuotes(this string value)

{

return value.Replace("'", "&#39").Replace("\"", "&#34;");

}

Text Property in UI

<asp:Label ID="Label1" runat="server" Text="<%$ Resources: LabelHeader %>"></asp:Label> // // Local Resource

<asp:Label ID="Label1" runat="server" Text="<%$ Resources:Messages, LabelHeader %>"></asp:Label> // Global Resource

Eval in Grid

<asp:TemplateField HeaderText="<%$ Resources:GridviewHeader %>">

<ItemTemplate>

<asp:LinkButton id="linkButton" Text='<%# DataBinder.Eval(Container, "DataItem.DocNumber") %>' ></asp:LinkButton>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="<%$ Resources:GridviewHeader %>">

<ItemTemplate>

<asp:LinkButton id="linkButton" Text='<%# Eval(“DocNumber") %>' ></asp:LinkButton>

</ItemTemplate>

</asp:TemplateField>

Document. getElementById

var lblNoError = window.document.getElementById('<%=lblNoError.ClientID %>');

Retrieving value from Server Side in JS

function HelloTime()

{

alert('<%= GetTime() %>');

}

// Code at Server Side

public string GetTime()

{

return DateTime.Now.ToString();

}

Thanks & Regards,

Arun Manglick || Senior Tech Lead


No comments:

Post a Comment