Click here to Skip to main content
15,905,563 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a dropdownlist in which i have given font names and i need to change the font of the label as soon as user select any font names(given in the dropdownlist).how can i adopt this without refreshing the page.my code is:
XML
<asp:DropDownList ID="drop1" runat="server" AutoPostBack="true"
                onselectedindexchanged="drop1_SelectedIndexChanged">
                 <asp:ListItem>SELECT</asp:ListItem>
        <asp:ListItem>Times New Roman</asp:ListItem>
        <asp:ListItem>Tahoma</asp:ListItem>


XML
<asp:Label ID="Label6" runat="server" Text="A GHHJJJ BHHHHH SFFFFFFFFF GGHGHHGGHGHHG" Font-Size="X-Large" ForeColor="White" Width="200px" Font-Names="Arial"></asp:Label>

also
C#
protected void drop1_SelectedIndexChanged(object sender, EventArgs e)
  {
      var select = drop1.SelectedItem.Value;
      if (select == "Times New Roman")
      {
          Label6.Font.Name = "Times New Roman";
      }
      else if (select == "Tahoma")
      {
          Label6.Font.Name = "Tahoma";
      }
      
}


my code works well,but my page is refreshing after each selection in the dropdownlist... Is there any javascript code for this??
also how can i integrate new fonts into my web page... im using visual studio 2010..
Posted
Updated 28-May-14 23:59pm
v2

 
Share this answer
 
v2
try that using javascript it id more faster than code behind.. :)

JavaScript
function ChangeStyle(FontValue) {

          document.getElementById("MyLabel").style.fontFamily= FontValue;
      }



ASP.NET
<asp:dropdownlist id="drop1" runat="server" onchange="ChangeStyle(this.value)" xmlns:asp="#unknown">
           <asp:listitem value="Arial Black">SELECT</asp:listitem>
             <asp:listitem value="Arial Black">Arial Black</asp:listitem>
           <asp:listitem value="Times New Roman">Times New Roman</asp:listitem>
           <asp:listitem value="Tahoma">Tahoma</asp:listitem>
       </asp:dropdownlist>

 <asp:label id="MyLabel" runat="server" text="My Name is Nirav" xmlns:asp="#unknown"></asp:label>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900