raviprakashg Posted January 11, 2007 Share Posted January 11, 2007 Dear friends.how to change readonly property in vb.net like-------------TextBox1.font.bold = true------------it shows error like "this is readonly property, can't change.."but i want to change font.bold property when i click a button.pl. help me.thanks Link to comment Share on other sites More sharing options...
aspnetguy Posted January 11, 2007 Share Posted January 11, 2007 this works fine in C# should work in VB (different syntax of course) TextBox t1 = new TextBox();t1.Font.Bold = true; Link to comment Share on other sites More sharing options...
jesh Posted January 11, 2007 Share Posted January 11, 2007 Are you talking about a System.Web.UI.WebControls.TextBox or System.Windows.Forms.TextBox? You're only going to be able to change the font in a TextBox if it is a System.Windows.Forms.TextBox. HTML/CSS doesn't allow you to style <input type="text" /> controls so System.Web.UI.WebControls.TextBox.Font is a read-only property. Link to comment Share on other sites More sharing options...
pulpfiction Posted January 11, 2007 Share Posted January 11, 2007 but this will not throw any error.... right??.aspx<asp:TextBox ID="txt" Runat="server" Width="100" />.aspx.vbProtected WithEvents txt As System.Web.UI.WebControls.TextBox...........txt.Font.Bold = True Link to comment Share on other sites More sharing options...
jesh Posted January 11, 2007 Share Posted January 11, 2007 I would think that it should give you an error. It might compile, but you should at least get a runtime error.According to Microsoft, in Visual Basic, the Font property is ReadOnly and in C#, there is only a getter defined (no setter).EDIT: of course, I don't have any idea because all of my style stuff is taken care of in CSS rather than compiled code I would prefer changing the CssClass rather than playing with the Font: txt.CssClass = "InputSelected" Link to comment Share on other sites More sharing options...
pulpfiction Posted January 11, 2007 Share Posted January 11, 2007 When I tried that code it compiled, did not even give a runtime error... Link to comment Share on other sites More sharing options...
aspnetguy Posted January 11, 2007 Share Posted January 11, 2007 did it change the font though? Link to comment Share on other sites More sharing options...
pulpfiction Posted January 11, 2007 Share Posted January 11, 2007 Yeah, when I entered some text in the textbox, it was bold.... Link to comment Share on other sites More sharing options...
aspnetguy Posted January 11, 2007 Share Posted January 11, 2007 Jesh I read that article you linked to. I think it is Font that is readonly. Font only has a getter but it's properties are settable....they even change some in the code below. Link to comment Share on other sites More sharing options...
jesh Posted January 11, 2007 Share Posted January 11, 2007 Jesh I read that article you linked to. I think it is Font that is readonly. Font only has a getter but it's properties are settable....they even change some in the code below.Interesting. Thanks for the clarification.Anyhow, like I said in my edit above, I typically set CssClass for an object in the compiled code rather than specific styles so that, if it came to it, I would simply have to change a CSS file rather than change some VB/C# and then completely rebuild (and/or republish) the entire website. Link to comment Share on other sites More sharing options...
aspnetguy Posted January 11, 2007 Share Posted January 11, 2007 Interesting. Thanks for the clarification.Anyhow, like I said in my edit above, I typically set CssClass for an object in the compiled code rather than specific styles so that, if it came to it, I would simply have to change a CSS file rather than change some VB/C# and then completely rebuild (and/or republish) the entire website.I agree that is the best method, leave it to MS to give you the option of bad programming. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now