What I have is few dropDownLists in few different templates of FormView.
And of course I can't get access to any of those.
What I want to do is get the same behavior for every DropdownList.
Is there any way to declare that DropDownList globally and reuse it or it should be done somehow with FindControl?
User control declarative syntax is very similar to syntax used to create an ASP.NET Web page.
The primary differences are that the user controls use an # Control directive in place of an # Page directive, and that the user controls do not include the html, body, and form elements around the content.
MSDN/creating usercontrol
Related
i have a template with some tokens like %{login}% or %{menu}%
i have also the related user controls Login and menu
the html string template comes from the db, my problem is that if i render the usercontrols with the Page.RenderControl or Server.Execute methods, i obviusly take the error "texbox/button must be placed inside a form tag with runat=server"
the login and menu usercontrols have inside the asp.net controls, so, how can i replace my tokens programmatically with the usercontrols leaving working the asp.net controls functionalities in the login and the menu?
Programmatically, you could read your string, and translate the tokens to the appropriate controls (which you probably already do), and, in so doing, you would instantiate an instance of your control and add it to an existing control collection, most commonly a PlaceHolder control.
Here's some reading on the topic: Dynamic Controls in ASP.NET
Cannot seem to grasp the concept of PageLink attributes for EpiServer listing controls. I need to understand this: "PageLink: Provides a page reference to a page; the children of that page will become the collection used." Supposing I'd like to use a MenuList - what sort of 'children' will be/can be used as a datasource to a menu control?
According to the EPiServer documentation
As PageLink is guaranteed to be unique among all pages in a certain
EPiServer instances, it is used in the following example to create
unique IDs and names for HTML check boxes. The code is used to present
the visitor with a selection of pages and allows them to select one or
more for further processing.
My understanding is that if you set a PageLink in your listing control, it will have access to the child pages based on that page.
What would be the best approach to set dynamic content from the database to controls in an aspx page?
My database consists of pages (index.aspx, home.aspx and so on) which consists of controls (DivStart, LabelDescription, and so forth).
The first technique that came to my mind was looping through all the controls in the page, looking for controls that have a certain class, e.g. "Cms_DivStart", and would then set the inner html for that control from the database control called "DivStart". The problem is only runat server controls shows up, and I don't want to make all controls server side.
I could store all the dynamic texts for a page in hidden variables and set it with jQuery when the page has loaded, but that would make the text not show up directly..
Any other ideas would be greatly appreciated.
Thanks
/Andreas
You could use asp:PlaceHolder tags, these don't add any html unless they are utilised.
You can write a custom class, I'll call it "CustomPage", that inherits the System.Web.UI.Page class. Then your pages can inherit "CustomPage". In this class, add methods to retrieve data, set custom properties and display your content in the available controls.
I am using ASP .NET (C#) and have a page with a listview linked to a sqldatasource.
The listview has a InsertItemTemplate which contains many textboxes. I want to make all the textboxes required via the RequiredFieldValidator (and the ValidatorCallOutExtender).
Is there a way to do this in the codebehind instead of the aspx page?
Ideally I would like the page to validate each control with the same method with only the error message changing.
I take it your question is about dynamically adding controls (and not about codebehind validation).
I didn't know and ran a few tests. It is possible to simply add (Validator)controls to the Controls property of the Form element, but controlling the order is not so simple (no Controls.Insert()).
So my advice would be not to use a plain TextBox but a UserControl. You could probably use Search&Replace to fix up the ItemTemplate.
I am using c#.net
I have different views within my webform, these all generally display different information except for three textboxes (arrival / seen / depart time). To try and cut down on code, I have created a UserControl which contains these three textboxes.
I have referenced the UserControl at the top of my webform and also within each view.
<%#Register TagPrefix="uc1" TagName="userTimes" Src="~/usercontrols/userTimes.ascx"%>
<uc1:userTimes id="userAppointmentTimes" runat="server"></uc2:userTimes>
can’t seem to access the textboxes from the code behind. I need to firstly populate the textboxes and also hold any updated information to be re-inserted back into the database if changed.
Also each textbox has two Validation controls:
First makes sure it is in time
format HH:MM
Second makes sure the arrival is
before the seen time etc
My two questions are:
How do I access the UserControl from
the code behind? I have read that I
need to use the FindControl but I
don’t understand why, when I know
what it is called.
Do I undertake the validation
(server side) within the UserControl
code behind or the webform code
behind?
Thanks in advance for any help.
Clare
1.) You can access the User Control by its ID from the page's code behind - userAppointmentTimes in your case. To access your TextBoxes within the webform you need to use the FindControl-Method at the User Control level. So something like userAppointmentTimes.FindControl("WhateverTextBoxID") should work. You need to cast the result to TextBox of course.
You can't access the text boxes because ASP.Net does not automatically expose them for you. So alternatively you can provide public properties to set/get values to/from your textboxes inside your user control.
Within the user control, you can access your textboxes by their IDs.
2.) Put the validation controls inside your user control.
By webform you mean it's all inside the asp.net form-tag or do you have an asp.net form like FormView nested inside? If the latter is true you need to use FindControl at the FormView level - formView.FindControl("userAppointmentTimes"). Otherwise the user control is accessible from page level via its ID.