Kentico 9 cms:cmsTextBox placeholder localization - kentico

I've duplicated the search box webpart so i can make changes. I'm trying to add a localization string to the placeholder attribute.
This isn't working:
<cms:CMSTextBox ID="txtWord" runat="server" EnableViewState="false" MaxLength="1000"
ProcessMacroSecurity="false" placeholder="<%= CMS.Helpers.ResHelper.GetString("kff.Search--PlaceHolderCopy")%>" />
nor does this:
<cms:CMSTextBox ID="txtWord" runat="server" EnableViewState="false" MaxLength="1000"
ProcessMacroSecurity="false" placeholder='<%= CMS.Helpers.ResHelper.GetString("kff.Search--PlaceHolderCopy")%>' />
I have a JS Snippet that does work, but i'm hoping to avoid copy in JS files.
var $searchField = $('.searchTextbox');
if ($('body').hasClass('ENCA')) {
// search field placeholder copy
$searchField.attr('placeholder', 'Search For Stuff');
}
else {
$searchField.attr('placeholder', 'Recherche');
}
Can I add the localization string to the server tag, or should it be done in the code behind. I'm not sure the best location in the code behind for this either, I can't see a Page_Load block.

You could add the following line in the SetupControl method in the codebehind:
txtWord.Attributes.Add("placeholder", ResHelper.GetString("kff.Search--PlaceHolderCopy"));
You cannot really use the <%= syntax to set properties of server-side controls.
Also, please note that the CMSTextBox control has a WatermarkText property, which might be what you are looking for. It uses the TextBoxWatermarkExtender control from the AjaxControlToolkit library.

There is no need to duplicate the webpart and have duplicate code just for something this simple. Just create a different webpart layout for that webpart and add the following code above the Panel:
<script runat="server">
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
txtWord.Attributes.Add("placeholder", ResHelper.GetString("yourstring"));
}
</script>

Related

How to get the value of a cms:FormField in a form layout script block?

I have a form that has a layout like so:
<cms:FormField runat="server" ID="fMemberType" Field="MemberType" />
<cms:FormField runat="server" ID="fEmployeeCount" Field="EmployeeCount" />
<asp:Literal runat="server" ID="test" Text="test" />
<script runat="server">
protected void Page_PreRender(object sender, EventArgs e)
{
test.Text = fMemberType.Value.ToString();
}
</script>
However this produces Object reference not set to an instance of an object. because it can't find fMemberType for some reason. Looking for the correct way of doing this.
It's worth noting that the form fields are dropdowns with depending flags set so changing them triggers a postback, or at least it would, but I set the webpart container to be an update panel so it's AJAXing which means the data isn't available in the page POST params. I could turn this off and grab the data from the POST data but wanted to know if there was a better way first.
So you're fully defining the fields and everything for your form? Why not use the DataForm control and dynamically create the form for you? You can then get the data like so: (formUserSettings is a cms:DataForm)
EditingFormControl ctrState = formUserSettings.BasicForm.FieldEditingControls["UserState"] as EditingFormControl;
Then do some checking and assign the value:
if (ctrState != null)
{
fState = ctrlState.Value;
}
Most likely the form value is not set until after the pre-render. Alen Genzic's recommendation will show that. May want to try OnInit.

Wordpress Technical Terms

I'm working on designing a site in WP, but I'm at a loss for the right words to google. What I'm looking for is a "text container that can be toggled". I have a syntax highlighting plugin for posting code, but I don't want the code to be visible in large blocks considering it may be a little distracting. I was wondering if anyone could link me to a plugin or give me the technical term for what I'm thinking of, where you can put the text in a group and then be able to toggle whether it is visible or not within the page.
It sounds like what you are looking for is simply applying a CSS class to the element and then using jQuery or some other JS library to toggle its visibility. Example below (code is not optimized in order to explain some of the concepts. This can, read "should", be cleaned up):
// This is HTML/CSS
<body>
...
<p>Here is some normal text.</p>
Show/hide source code for displayText method
<div class="source_code" id="source_code_for_displayText_method">
// Groovy code
...
public void displayText(String message) {
outputStream.write(message)
}
...
</div>
...
Show/hide source code for download method
<div class="source_code" id="source_code_for_download_method">
// Groovy code
...
GParsPool.withPool(threads) {
sessionDownloadedFiles = localUrlQueue.collectParallel { URL url ->
downloadFileFromURL(url)
}
}
...
</div>
...
Show/hide all source code sections
...
</body>
You can default all source code sections to hidden:
// This is CSS
.source_code {
display: hidden;
}
Then you would use JS to provide the toggle ability:
// This is JavaScript
// This toggles a specific section by using an id ("#") selector
$('#source_code_displayText_method_toggle_link').onClick(function() {
$('#source_code_for_displayText_method').toggle();
});
// This toggles all source code sections by using a class (".") selector
$('#source_code_all_toggle_link').onClick(function() {
$('.source_code').toggle();
});
Some thoughts:
If you toggle all sections, you need to determine what the current state is -- if some are currently shown and others hidden, this will invert each. If you want "hide all" and "show all", then use .hide() and .show() respectively.
If you are manually adding the source code sections and want semantic selectors, the above is fine. If you are building some kind of automation/tool to allow you to repeat this, you'll probably want to use generated ids and helper links, in which case it would look like:
.
// This is HTML/CSS
<body>
...
<p>Here is some normal text.</p>
Show/hide source code for displayText method
<div class="source_code" id="source_code_1">
// Groovy code
...
public void displayText(String message) {
outputStream.write(message)
}
...
</div>
...
Show/hide source code for download method
<div class="source_code" id="source_code_2">
// Groovy code
...
GParsPool.withPool(threads) {
sessionDownloadedFiles = localUrlQueue.collectParallel { URL url ->
downloadFileFromURL(url)
}
}
...
</div>
...
Show/hide all source code sections
...
</body>
With the JavaScript to handle id parsing:
// This is JavaScript
// This toggles a specific section by using a dynamic id ("#") selector
$('.source_code_toggle_link').onClick(function(elem) {
var id = $(elem).attr("id");
// Split on the _ and take the last element in the resulting array
var idNumber = id.split("_")[-1];
var codeBlock = $('#source_code_' + idNumber);
codeBlock.toggle();
});

How to get the value of Radiobutton Listitem using Javascript

I want to get the value of the selected item of a radiobutton List using javascript.
My code is:
<asp:RadioButtonList runat="server" ID="Radio" RepeatColumns="3" CssClass="textfont">
<asp:ListItem Value="1" Selected="True">First</asp:ListItem>
<asp:ListItem Value="2">Second</asp:ListItem>
<asp:ListItem Value="3">Third</asp:ListItem>
</asp:RadioButtonList>
And this is my Javascript code:
<script type="text/javascript">
function sendParameters() {
var Id = '<%=HiddenField1.Value%>';
var ddl1 = document.getElementById("Radio").checked;
</script>
How to proceed?
First of all please view the source of the resulting web page and post the resulting radio button html. This will make it easier to answer because then the question comes down to plain HTML and jQuery.
The Reason is asp often changes the name of the ID, unless you add ClientIDMode="Static" to your control.
Once that is done this should do it:
var chosenValue = $('input:radio[id="Radio"]:checked').val();
alert(chosenValue);

c# fill something on html page

how can I fill "MyUserName" on
<td width="18%" class="more"><div align="right">¿¿¿¿¿¿ </div></td>
<td width="82%">
<font color="#FFFFFF" face="MS Sans Serif, Tahoma, sans-serif">
<input type=text name="QTitle" size=51 maxlength=100 class=violet>
</font>
</td>
i try in c# but it not work please help
private void webBrowser2_DocumentCompleted(object sender,
WebBrowserDocumentCompletedEventArgs e)
{
}
private void LoadProfileInformation()
{
DataSet dsNew = new DataSet();
//Some code to fetch information if you store it in a DB
//else you can put in static info if you may want.
//so you will nto need the dataset.
QTitle.Text = "MyUserName";
}
You can store it in the class then access it with code behinds like <%= myVar %> in your front end.
if you want to modify the values of divs on the front end then you need to use asp tags like
<asp:label runat="server" name="Qtitle"> </asp:label>
First of all you really need to think about moving to newer versions of XHTML/HTML! (I suggest you that because of your markup code).
In the other hand, in order to get your "QTitle" text set from server, you'll need to set "runat" attribute to "server" in your input, but, if you're using standard (X)HTML elements, you won't have such property "Text".
I suggest you to use a server control like TextBox which has the whole "Text" property:
<asp:TextBox ID="QTitle" runat="server" CssClass="Violet" />
Some server code-behind:
QTitle.Text = "Hello world";
Another suggestion is you won't be setting any property after PreRender ASP.NET Page life-cycle event.
Is the mark-up at the top of your question the resulting html or the source code for the form you are working with? If this is in-fact your asp.net form, try replacing the input tag with the following...
<asp:TextBox id="QTitle" runat="server" />
If the form is properly linked to the C# codebehind file you are using, QTitle.Text should now be accessible.

Dynamically setting the ListId in the <SharePoint:ListView> control

Is there a way to dynamically set the ListId field in the ListView control. We cannot guarantee that the list we are interested in has a consistent GUID between installations (The list is deployed as part of a site template that we do not control). I've tried using the PreInit event to set a variable (see the list guid: section. If I remove the ListView tag, I see the proper GUID printed out. So I'm collecting the GUID correctly. However, The listview control errors out with the following message "Guid should contain 32 digits with 4 dashes". This tells me that the tag is not getting the variable set. Is this correct? Is there another way to specify the list to use?
Can this be done?
Sample code follows:
<%# Register TagPrefix="Sharepoint" ...details deleted.. %>
<br>
...stuff deleted.
<br>
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
... more stuff deleted...
<p>list guid: <%=ListGuid %>
<Sharepoint:ListView ListId="<%=ListGuid %>" Enabled="true" runat="server" />
<p>
</asp:Content>
<script runat="server">
string ListGuid = string.Empty;
protected void Page_PreInit(object sender, EventArgs e)
{
SPSite Site = SPContext.Current.Site;
using (SPWeb HelpDesk = Site.OpenWeb("HelpDesk"))
{
SPList list = HelpDesk.Lists["Charge Numbers"];
ListGuid = list.ID.ToString();
}
}
</script>
Having server-side code like you do that gets injected into more server side code is a little weird and seems unlikely to work. What does the SharePoint log say about the list ID that it's trying to load? My guess is that it's not really trying to load the list represented by the GUID that you're setting in your ListGuid variable.
Instead of trying to force some global ListGuid variable to have the correct guid, why not just set the control's ListId property inside your application page's Load event handler?
In the aspx file:
<SharePoint:ListView Id="lv" runat="server" />
In the application page's codebehind:
protected ListView lv
In the Load event:
SPList list = HelpDesk.Lists["Charge Numbers"];
Guid myguid = list.ID;
lv.ListId = myguid.ToString();
I think the error message you are receiving is telling you what's going wrong... the ToString() is converting the GUID to an invalid format. There is an overload for the tostring
list.ID.ToString("N");
list.ID.ToString("D"); (this is the default)
list.ID.ToString("B");
list.ID.ToString("P");
... Try them all

Resources