I have the checkbox seen below,and I want to do something like this
<asp:CheckBox ID="Accept" runat="server">
Accept terms
But I want the to be part of the asp CheckBox, so that I can do something like this:
<asp:CheckBox ID="AcceptCheckBox" runat="server" Text="Accept" terms first" />
Is that possible, and if so, how do you express it?
Using label
You can use the label tag as:
<asp:CheckBox runat="server" ID="AcceptCheckBox" Text="" />
<label for="<%=AcceptCheckBox.ClientID %>">
<a target="_blank" href="terms.html">terms</a> first
</label>
This is the test output: http://jsfiddle.net/5SVDk/1/
Using asp:Label control
From the idea of #richard-deeming we can also use an asp:Label control to avoid the write on page, and the code will be:
<asp:CheckBox runat="server" ID="AcceptCheckBox" Text="" />
<asp:Label runat="server" AssociatedControlID="AcceptCheckBox">
<a target="_blank" href="terms.html">terms</a> first
</asp:Label>
Using the asp:CheckBox only
You can also use the code behind to add the link as:
AcceptCheckBox.Text = "<a target=\"_blank\" href=\"terms.html\">terms</a> first";
and simple
<asp:CheckBox runat="server" ID="AcceptCheckBox" />
all tested and they render the same html
This is working for me
<asp:CheckBox ID="CheckBox1" Text="go to <a href='http://www.yahoo.com'>yahoo</a>" runat="Server" />
<asp:CheckBox ID="Accept" Text='Accept terms' runat="server" />
Related
I have a situation where there is HTML inside an anchor tag. And the author should be able to edit both the anchor (href) & other fields.
aspx:
<asp:Repeater ID="rpEvents" runat="server" ItemType="Sitecore.Data.Items.Item">
<HeaderTemplate>
<div class="col-md-3">
</HeaderTemplate>
<ItemTemplate>
<a href="offers/spring.html">
<sc:Image runat="server" Field="offer image" Item=<%#Container.DataItem%> />
<h3><sc:Text runat="server" Field="Offer Title" Item=<%#Container.DataItem%> /></h3>
</a>
</ItemTemplate>
<FooterTemplate>
</div>
</FooterTemplate>
</asp:Repeater>
I would do this by turning the <a> into <asp:Hyperlink> & assigning its NavigateURL property from code behind, but then the author cannot edit it in experience editor.
How is this done in Sitecore.
You can wrap the other HTML elements using the Link field, which will allow all fields to continue to be edited from the Experience Editor:
<ItemTemplate>
<sc:Link Field="Offer Link" Item="<%# Container.DataItem %>" runat="server">
<sc:Image Field="Offer Title" Item="<%# Container.DataItem %>" runat="server" />
<h3><sc:Text Field="offer image" Item="<%# Container.DataItem %>" runat="server" /></h3>
</sc:Link>
</ItemTemplate>
The Link can still be set, the image changed or the separate text field edited:
An option is to use the sc:EditFrame inside a repeater, that looks like:
<asp:Repeater runat="server" ID="AccordionRowRepeater">
<ItemTemplate>
<my:AccordionRow runat="server" ID="AccordionRowItem" RowItem="<%# Container.DataItem %>" />
</ItemTemplate>
</asp:Repeater>
And the Row control
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="AccordionRow.ascx.cs" Inherits="mynamespace.Controls.AccordionRow" %>
<sc:EditFrame id="EditAccordionItem" runat="server" Buttons="/sitecore/content/Applications/WebEdit/Edit Frame Buttons/Accordion Item">
<li class="<%= LiClass %>">
<a class="trigger" href="#"><sc:Text runat="server" ID="ItemTitle"/></a>
<div class="collapsible">
<sc:Text runat="server" ID="ItemText" />
</div>
</li>
</sc:EditFrame>
And add a Field Editor Button to the Edit Frame Buttons
More about this Accordion example see User friendly developing with the Sitecore Experience Editor
Or, I often use this simple solution. It also give you the opportunity to display some help text to the content editor.
<div runat="server" id="PageditorDiv" Visible="False">
URl: <sc:Link runat="server" ID="link"/>
</div>
And in the code Behind.
if (Sitecore.Context.PageMode.IsPageEditor)
{
PageditorDiv.Visible = true;
}
I have many checkBoxes HTML controls runat server, I want to disable and enable them together.
I've tried to set them in an ASP.Net Panel and set the panel disabled, but they stayed enabled.
Any idea ?
The code
<asp:Panel runat="server" ID="PrivilegesCheckList" >
<input id="adminPrivilegeCheckBox" type="checkbox" runat="server" />
<asp:Literal ID="Literal1" runat="server" Text="<%$ Resources:Resource, itemAdminPrivilege%>" />
<br />
<input id="accountPrivilegeCheckBox" type="checkbox" runat="server" clientidmode="Static" />
<asp:Literal ID="Literal2" runat="server" Text="<%$ Resources:Resource, itemAccountManagerPrivilege%>" />
<br />
<input id="employeePrivilegeCheckBox" type="checkbox" runat="server" clientidmode="Static" />
<asp:Literal ID="Literal3" runat="server" Text="<%$ Resources:Resource, itemEmployeeManagerPrivilege%>" />
<br />
<input id="orgChartPrivilegeCheckBox" type="checkbox" runat="server" clientidmode="Static" />
<asp:Literal ID="Literal4" runat="server" Text="<%$ Resources:Resource, itemOrgChartPrivilege%>" />
</asp:Panel>
Using JavaScript you may do something like this :
var controls = document.getElementById("<%=panel1.ClientID%>").getElementsByTagName("input");
for (var i = 0; i < controls.length; i++)
controls[i].disabled = true;
Note that ASP.Net produces dynamic Id's for server side controls (panel here ) , that tends to use document.getElementById("<%=panel1.ClientID%>") above.
Setting the Panel to disabled would work for asp Controls like CheckBox but not for an input with runat=server. This checkbox is disabled because the panel has Enabled=false:
<asp:Panel ID="Panel1" runat="server" Enabled="false" >
<asp:CheckBox ID="CheckBox1" runat="server" />
</asp:Panel>
You could also easily fix this with jquery (client side):
$('#mypanelClientID input[type=checkbox]').attr('disabled', true);
I am helping my daughter build an asp.net website that has an Access database. We are using a DataList with a couple fields inside the ItemTemplate. The one that is giving me trouble is the Hyperlink. The code is below. When the page loads the hyperlink renders like this:
<a id="ContentPlaceHolder1_DataList1_lnk_6" href="#http://www.washingtonfaire.com/#" target="_blank">Washington Midsummer Renaissance Faire</a>
But when I click on the link, it tries to navigate to "http://localhost:1852/BOOMPiratesB/Raids.aspx#http://www.washingtonfaire.com/#"
What are we doing wrong?
Here is our code.
<asp:DataList ID="DataList1" runat="server" DataSourceID="AccessDataSource1">
<ItemTemplate>
<asp:HyperLink id="lnk" runat="server" NavigateUrl='<%# Eval("Link") %>' Target="_blank" Text='<%# DataBinder.Eval(Container.DataItem, "VenueName")%>'>
</asp:HyperLink>
<br />
<asp:Label ID="DateTextLabel" runat="server" Text='<%# Eval("DateText") %>' />
<br />
<asp:Label ID="CityStateLabel" runat="server" Text='<%# Eval("CityState") %>' />
<br />
<br />
</ItemTemplate>
</asp:DataList>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/my.mdb"
SelectCommand="SELECT [VenueName], [Link], [DateText], [Season], [DateStart], [CityState] FROM [qpgRaid]">
</asp:AccessDataSource>
I cannot see where the extra # signs are coming from. They don't appear to be in the field in the table.
It's very puzzling. And insight would be most appreciated.
Have a look at this question
I guess you are using an access hyperlink column to store the link. If you convert it to a text column it should start working fine, or you may have to strip the '#'s manually.
Greetings!
I have a "code builder" page where users select various radio buttons and it generate HTML markup (mostly SCRIPT tags) that they can use on their page to display some data. There is also a "preview" area so they can see the results before they copy/paste the code in their site. The form exists in a FormView control and is wrapped by an UpdatePanel like so:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FormView ID="FormView1" runat="server" DataSourceId="XmlDataSource1">
<ItemTemplate>
<div id="configArea">
<ul>
<li>
<%# XPath("Steps/Step1/ServerStatus") %><br />
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="OneA" Checked="true" AutoPostBack="true" Text='<%# XPath("Steps/Step1/YesOption") %>' />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="OneA" AutoPostBack="true" Text='<%# XPath("Steps/Step1/NoOption") %>' />
</li>
<li>
<%# XPath("Steps/Step1/Uptime") %><br />
<asp:RadioButton ID="RadioButton3" runat="server" GroupName="OneB" Checked="true" AutoPostBack="true" Text='<%# XPath("Steps/Step1/YesOption") %>' />
<asp:RadioButton ID="RadioButton4" runat="server" GroupName="OneB" AutoPostBack="true" Text='<%# XPath("Steps/Step1/NoOption") %>' />
</li>
<li>
<%# XPath("Steps/Step1/IPAddress") %><br />
<asp:RadioButton ID="RadioButton5" runat="server" GroupName="OneC" Checked="true" AutoPostBack="true" Text='<%# XPath("Steps/Step1/YesOption") %>' />
<asp:RadioButton ID="RadioButton6" runat="server" GroupName="OneC" AutoPostBack="true" Text='<%# XPath("Steps/Step1/NoOption") %>' />
</li>
</ul>
</div>
<div id="copyCode">
<%# XPath("Steps/Step2/CopyPasteCode") %><br />
<asp:TextBox ID="Textbox1" runat="server" TextMode="MultiLine" Width="300" Height="300" />
</div>
<div id="previewArea">
<%# XPath("Steps/Step3/PreviewTitle") %><br />
<asp:Literal ID="Literal1" runat="server" />
</div>
</ItemTemplate>
</asp:FormView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" XPath="Root/Data" />
It successfully generates the code in the copycode TextBox (TextBox1), which may look something like this:
<script src="http://example.com/src/Constants.js"></script>
<script>
showIPAddress = 0;
DisplayServerStatus();
</script>
At the same time, I update the "preview" area's Literal control (Literal1) with the text from the copycode TextBox (TextBox1). The preview is displayed perfectly when not inside an UpdatePanel, but does not work when it is (and I'd prefer to use an UpdatePanel to prevent page refreshing). I do the update of the "preview" area and copycode text during the PreRender event:
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
UpdateCodeSnippetAndPreviewArea();
}
Any ideas why the preview doesn't update when it's in an UpdatePanel?
The reason it is not updating when using an UpdatePanel is that the ASP .NET AJAX framework does not process any inline javascript returned by the server. Look at using the ScriptManager.RegisterStartUpScript method on the server side to register execution of inline javascript. Essentially you could use this method to initiate execution of custom javascript once the panel is updated. In your case, your custom javascript would need to interpret the preview script appropriately (i.e. detect script tags, register them dynamically then execute the given functions).
Hope this helps!
Rohland
I'm trying to separate my presentation and logic as much as I can, but there's one problem.
How can i set the text-property to a dynamic value from my design file? I want to do like this:
<asp:Textbox id="txtUrl" runat="server" Text="<%= user.URL %>" />
But this will fail. Am i forced to do this from code behind?
<asp:Textbox id="txtUrl" runat="server" Text="<%# user.URL %>" />
It's all about the #. but it won't get set till txtUrl.DataBind() or something higher in the object heirarchy (like the Page) calls DataBind().
How about this :
<input type="text"
id="txtUrl" name="txtUrl" runat="server"
value='<%= user.URL %>' />
You can use binding instead of evaluation.
This code binds a text box's Text property to a user's Url property returned by MyData.GetLoggedInUser(). This allows for 2-way binding.
<asp:FormView ID="UserView" runat="server" DataSourceID="LoggedInUser">
<ItemTemplate>
<asp:TextBox ID="tb"
runat="server"
Text='<%# Bind("Url") %>'></asp:TextBox>
</ItemTemplate>
</asp:FormView>
<asp:ObjectDataSource ID="LoggedInUser"
runat="server"
SelectMethod="GetLoggedInUser"
TypeName="MyData">
</asp:ObjectDataSource>