如何根据下拉列表的值更改标签的字体
问题描述:
我有一个下拉列表,其中我已经给出了字体名称,一旦用户选择了任何字体名称(在下拉列表中给出),我就需要更改标签的字体.如何在不刷新page.my的情况下采用此字体?代码是:
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:
<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>
<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
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";
}
}
我的代码运行良好,但是在下拉列表中的每个选择之后我的页面都正在刷新...是否为此使用任何javascript代码?
还如何将新字体集成到我的网页中呢……我正在使用Visual Studio 2010..
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..
答
^ ]
尝试使用javascript标识比后面的代码更快..:)
try that using javascript it id more faster than code behind.. :)
function ChangeStyle(FontValue) {
document.getElementById("MyLabel").style.fontFamily= FontValue;
}
<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>