What is the difference between the asp:label and the html label ?
I know that the first one is rendered on the server so basically it returns a span tab, but what is its use? What are the cases in which one would want to use a HTML tag and in what would one want to use the asp:label? I know that if I put it as an ASP control I can programatically access it, but what are differences between the 2 purely in terms of designing the UI?
If the asp:Label has its "AssociatedControlID" attribute value set to the ID of form control on the page then it will actually be rendered as a HTML label control (with the "for" value set to the client ID of the same control) when rendered to the client.
The HTML label control is designed strictly to provide a label/caption for a form control (i.e. an input, select or textarea) which describes the purpose of the form control to the user (see https://developer.mozilla.org/en-US/docs/HTML/Element/label). The label is normally (strongly) associated with the particular input using the "for" attribute which should be the ID of the input. This is particularly useful for those with accessibility needs who are not able to interpret the relationship based solely on proximity of the text and control. Imagine a form with several textboxes but no way to know which input was required in each one. The HTML label control is not used for general text outside of this context.
If the "AssociatedControlID" attribute of the asp:Label has no value then the control will simply be rendered as a span control containing the text. Some developers like to use asp:Labels to output text onto the page, giving the control a dual purpose (unlike the HTML counterpart). I personally prefer to use asp:Literals for this purpose as it gives me more control of the containing markup.
The reason to choose the asp:Label as opposed to the native HTML label control is that you can easily interact with it using server side code, for example changing the text or CssClasses in response to server events, and you can enter the server ID as the "AssociatedControlID" value which will automatically be rendered as the client ID (e.g. shown as "ct100_MainContent_TextBox1" as opposed to "TextBox1") in the "for" value on the client.
Related
New to access and I am trying to build a database to organize some in-house parts. I currently have a table containing measurements, photos, etc and having it displayed through a form. The form would show these values and the image of said part. Id like to add two buttons to the form that will
pull up a pdf of the drawing file and
List item processing specs.
So far I have tried creating hyperlinks or embedding the files into the form, but if you were to search for another part, it would direct me to the same two files no matter what part is displayed
I wanted to know if was possible to make it so if you change the search for the data displayed and how to go about implementing it if it is.
I don't know the full circumstances of course, but typically you would add a TextBox control to the form that is bound to the hyperlink field in the table.
If you wish to use a Button instead then I would probably use the Current event of the form (triggered as the user moves between records) to change the hyperlink properties of the button to those of the (bound) hyperlink field. These properties are:
Hyperlink Address, Hyperlink SubAddress and Hyperlink Target
(and the button's Caption)
It might require code on other events as well, to cover different eventualities.
I'm having issues getting a control to pass its value back to my server from the browser. Essentially, what I need is a LiteralControl that can be pushed onto the page, modified by some JavaScript, and then pass its entire contents back.
What I'm doing: I'm working with an SVG image. I need to send whatever pre-initialized value (display elements/content) to the browser. Then the user can interact with the image via JavaScript. Whenever they submit the form, I need to get the new/modified image back.
I made a custom control that outputs the SVG element, and allows you to set custom width, height, and viewbox attributes. It has a style element that you can provide content for, and a script element that you can also provide some content for. I've set up a ScriptDescriptor for all the properties that should be modified on the browser. I built an SvgImage.prototype and an SvgImage.descriptors JavaScript class, and registered my namespace and class in JavaScript. My JavaScript is all making it to the browser, but the control isn't added to the Request.Form elements coming back in.
Is there any way to get the control added to the Request.Form elements without creating a hidden field and dumping the content into it?
As I mention in my comment, I am unaware of any native ASP.NET control that would allow you to do this.
All form information posted back to the server has to be (to my knowledge) contained within an <input> control. (As I'm sure you're aware, ASP.NET can only work with standard form processing as supplied by your average browser.)
So I think you're looking at transfering the SVG information into a hidden control (an invisible <textarea> / <asp:TextBox TextMode="Multiline"/> makes most sense) before the post-back takes place.
Another option could be to use AJAX, although if you only want the the information at the point of post-back, you could run into trouble with the timing of it... so I can't see it being much use (but just mentioning it as an option).
We have a win application that shows a web form in a web browser.
In order to get data from this web form we are using a hidden text box and get its text using HtmlDocument object of web browser control.
I want to make an abstraction of this web form that has this text box element so that other forms can use this abstraction.
I made a web control and put the text box on it.I thought that if I put this control on my page it would have the text box.When i ran my application I noticed that the text box had been rendered but had its control name in its name (WebControl$TextBoxName) and its id(WebControl_TextBoxName) and the win app throw an exception since it couldn't find the element by its id(TextBoxName).
So here's my question:
How can I make an abstract web form/web control that has some elements on it and I can use it to make my final forms have these elements on them? (their names and ids should not be changed)
Thank you for your help
dotNet 4.0 supports static id's so they don't get mangled, read up on Client Id Mode
Alternatively, you could override the render of your control to output a standard html hidden form field with whatever ID you want, and then also add a custom property that will return the textbox that will hide the fact that it isn't an asp.net server control.
Though I've never used the browser control in WinForms, I think what you want to use is a Master Page. Assuming what you're rendering in the browser control is an ASPX page, create a Master Page with the hidden text box that you want to grab your data from, and tell all of the pages you want to have that common control on to use your Master Page. When the page renders, the control id will then be "ctl00_TextBoxName". There is no way of getting around the ID concatenation, since unique IDs are needed and that's the only way to guarantee uniqueness with all the nested control abilities of ASP.NET. However, doing this will guarantee you always have that control named the same on every new form you create that inherits the Master Page. Hope that helps!
In summary (because who reads paragraphs?):
Create Master Page
Place your common control in the Master Page
Have your Form inherit the Master Page
You can read up on how Master Pages work in MSDN's Documentation.
Is it possible to have a custom server control with a single template (meaning the user can put any text they want) without having to require the an "ItemTemplate" like in a FormView control?
I would want the control in Source View to look like this
<foo:mycontrol runat="server" id="controlid">
User puts whatever html content they want here
</foo:mycontrol>
INSTEAD OF THIS
<foo:mycontrol runat="server" id="controlid">
<ItemTemplate>
User puts whatever html content they want here
</ItemTemplate>
</foo:mycontrol>
My custom server control needs to add 2 asp.net panel controls and the ajax collapsiblepanel control. one panel will be the expand/collapse panel and the other panel is what I would want to put the user text into and then have the collapsible panel collapse and hide the panel.
I know how to do this (at least I think I do) creating a composite server control and using ITemplate but that requires the child <ItemTemplate> tag in source view.
Any ideas?
I haven't tested this but I would think you could do this by inheriting from the literal or label control and then reading/writing to the Text property.
p.s. next time when you post a question check the preview to see if it's readable and format code with 4 spaces in-front so it's actually shown and syntax highlighted.
Hmm why don't you use an approach where you just specify the controls to be collapsed. For instance your declaration could look like
<foo:mycontrol runat="server" id="controlid" TargetControlId="pnlToCollapse" />
Internally, your mycontrol gets an instance of the specified TargetControlId by using the FindControl method (here's a recursive version). The same could be done for the 2nd panel you need.
Your server control does therefore just take configuration info and doesn't render anything, but controls the rendering of the other panels in this case. It is a much more flexible solution in my eyes.
Juri,
I should have clarified that this control might be used by non-developers or developers who we do not want to require too much knowledge of setting properties so I'm trying to develop a control where they would drag it on like a panel and just enter text and maybe set one property which would be the title. I was able to create a compositecontrol which I created a title panel, the collapsible panel and utilized the asp.net ajax collapsiblepanel control. I had to add an Template though which I would prefer not to do.
Darrell
I imagine having to interact with Gmail is a necessity for most programmers. Gmail's control for associating labels to emails is monumentally effective UI behavior.
For those unfamiliar with the behavior, it's basically a button-initiated pop up panel (drop down UI effect) containing:
1) a text entry box
2) scrollable multi-checkbox list
and
3) a submit button.
...all neatly and tightly stacked on top of each other. This panel allows the user to type into the search box to control the items of the scrollable checkbox list in real time. Once all desired items are selected, the submit button initiates the server action.
I imagine the most challenging aspect would be getting the the text box control to govern which items are in the scrollable checkboxlist without having to hit the server (or ajax at most).
What I would do is to create a ASP.net server control and do the filtering with JavaScript. Since all of the items are displayed from the beginning, I thing there is no need for doing any Ajax call (it's not like autocompletion where it would make sense). The submit button would then be just a normal postback to the server as usual.
For providing the real-time javascript filtering you could think of implementing a servercontrol that follows the databinding mechanism of .Net, accepting a datasource and providing an appropriate databind method. Maybe it would be convenient then to convert the passed data to some JSON format that can then be easily loaded and managed on the client-side by some appropriate JavaScript function.