To begin with, your problem has nothing to do with the C # language. The language is the same for WinForms, as well as for ASP.NET, ASP.NET MVC, WPF, WCF and everything else.
The difference in your two code fragments is not caused by differences in the language (it is, I repeat, the same everywhere), but by the fact that these fragments use different classes from different assemblies that have similar names and fields for some (not quite random) coincidence. / properties / methods. (In the first case, you have the System.Drawing.Font class from the System.Drawing.dll assembly, and in the second System.Web.UI.WebControls.FontInfo from the System.Web.dll assembly) In other words, you need not hope that By taking code from a WinForms application and stuffing it into an ASP.NET application, you won’t get a bunch of errors.
Now for your code. As far as I understand, you want to change the font of the label when selecting an item from the drop-down list. Your mistake is that the Font property of the controls does not have a setter, and therefore write something like
MyControl.Font = new Font(...);
You can not. However, you can change the properties of the font itself. For example:
<asp:DropDownList runat="server" ID="Drop" OnSelectedIndexChanged="OnChanged" AutoPostBack="True"> <asp:ListItem>Times</asp:ListItem> <asp:ListItem>Arial</asp:ListItem> <asp:ListItem>Verdana</asp:ListItem> </asp:DropDownList> <asp:Label runat="server" ID="Label1" Font-Names="Verdana" Font-Size="10pt" >Caption</asp:Label> protected void OnChanged(object sender, EventArgs e) { Label1.Font.Name = (sender as DropDownList).SelectedItem.Text; }
And finally - if you want to make a web application, then use ASP.NET MVC for this, it is more convenient, logical and to the best extent separates the view and the model. And it is much more convenient to carry out manipulations on changing the contents of one control depending on the other using knockout.js