API
Version 7.x > API > Help with javascript and Web part components View modes: 
User avatar
Member
Member
eric.dofonsou.consultant-cbd - 1/11/2013 9:39:48 AM
   
Help with javascript and Web part components
Hello
I'am new to Kentico development.

I'am trying to build a custom component. What I want:

1-a component that will have a text area (ie : cms:CMSTextBox).
2-A button next to it that when clicked will open a new navigator window to the value (URL) entered in the text area component).

Right now I want to do this using Javascript (JQuery). However I'am not able to find a way to get the value of the text area using pure javascript, is this possible ?

Here is a dumb of the ascx of my component :
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="LinkTextBoxControl.ascx.cs"
Inherits="CMSFormControls_Basic_LinkTextBoxControl" %>
<cms:CMSTextBox ID="textbox" runat="server" />
<cms:CMSButton ID="btnOpenUrl" runat="server" CssClass="ContentButton" EnableViewState="false"
onClientClick="window.open('{textboxe.text}');"/>

Can anyone help me with this ?

Eric,

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 1/15/2013 2:48:52 PM
   
RE:Help with javascript and Web part components
Create a js file with your webpart and in that file create a function in it like so:
function openWindow(txtClientID) {
var oTxt = document.getElementById(txtClientID);
window.open(oTxt.value);
}

<cms:CMSButton ID="btnOpenUrl" runat="server" CssClass="ContentButton" EnableViewState="false"  onClientClick="openWindow(<%# textbox.ClientID %>);"/>
I haven't tested this but this should help you.

User avatar
Member
Member
eric.dofonsou.consultant-cbd - 1/16/2013 9:51:16 AM
   
RE:Help with javascript and Web part components
Thanks for the feedback greatly appreciated.

Why the external javascript file ?
Cant't inline everything in a single line (like below) ?

<cms:CMSButton ID="btnOpenUrl" runat="server" CssClass="ContentButton" EnableViewState="false"
onClientClick="window.open(document.getElementById(<%# textbox.ClientID %>).value);"/>

by the way that did not work but I will try to debug it ...

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 1/16/2013 5:34:19 PM
   
RE:Help with javascript and Web part components
You could do inline I guess, just easier to put the script in an external file and make changes there I think. Your script should look like this:

<cms:CMSButton ID="btnOpenUrl" runat="server" CssClass="ContentButton" EnableViewState="false"
onClientClick="window.open(document.getElementById('<%# textbox.ClientID %>').value);"/>
Notice the ' ' around the <%# %> tags.