Hi guys, quick question. When I work with asp.net controllers (so say a TextBox or a Label) if I want to get what's inside them I will use the Text property: for asp.net listboxes instead I use the Value property. If I instead, say, I ditch completely the asp.net controllers and use equivalent HTML elements (input, textarea) I have to use the Value attribute when I use them within a asp.net environment (although for the HTML select tag I can still use the Text property). So, in view of the above, is there some kind of rule that tells me when to use what?
I know it can be confusing. For example, a textbox in asp.net renders as an input element. The text property of a textbox is the input elements value property.
You'd have to refer to MSDN for documentation.
um, yes it is confusing. OK, so you're effectively saying that whenever I use an asp controller or a HTML tag I should look them up on the MSDN ro check what property to use in C#? So, say the textBox http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox_properties(v=vs.110).aspx, there is no "value" property listed, so I know I can't use that. Cool, this for a sp textBox. How about a input html tag though, MSDN won't have anything on that, but I still need to know - I appreciated you clarified this specific instance above so I am more talking in general terms now - whether I need to use a Text or a Value property for a HTML tag used in ASP.NET
So yes, you are correct...you'd have to check with MSDN documentation to know excactly what properties, methods, etc.. are avaiable for the asp.net control.
If you are using Visual Studio, that documentation is really built in via Intellisense. So for example, in your code-behind...as you are typing the ID of the textbox and you hit the period, Intellisense would kick in and show you a small tip/popup with the available methods, properties, etc. for that specfic control or whatever object you are working on.
So in your aspx page, you dont have to only use asp.net controls. You can include html elemnets as well. if you want to be able to access their properties in the code-behind page, you have to add the attribute "runat = "server" and then in your code behind, you'll be able to access them. Say for example you add a span element. But you may simply just want to add a label control since the label control renders as a span element. its up to you..there is no right or wrong way in this case. it depends on what you have, what you want, etc..
<span id="span1" runat="server" ></span>
in your code behind, you would be able to do this...
span1.InnerHTML = "My Span Element";
by adding the runat="server" you are turning that html elemnet into a HtmlGenericControl.
Ok thanks for that, yes I am using visual studio, still finding my way around things :-)