0

I have a textarea and i am using a plugin for that textarea. In that plugin there is a function getCode() which will return the value of the textarea. That function will be called like - textarea_id.getCode();

I am using ASP.NET in which i have declared the textarea (runat=server), and the textarea'a id i can get but when i am writing the following code it is not calling the method.

'<%= txtName.ClientID %>'.getCode(); 

But if i am writing then it is working fine.

ctrl001_txtxName.getCode();

Because the first one is a string and the second one i guess is an object. If so then how to overcome this problem. Can anyone please help?

Code Block

Plugin = function(obj)
{
    var self = document.createElement('iframe');
    self.textarea = obj;
    self.textarea.disabled = true;
    self.textarea.style.overflow = 'hidden';
    self.style.height = self.textarea.clientHeight + 'px';
    self.style.width = self.textarea.clientWidth + 'px';
    self.textarea.style.overflow = 'auto';
    self.style.border = '1px solid gray';
    self.frameBorder = 0; // remove IE internal iframe border
    self.style.visibility = 'hidden';
    self.style.position = 'absolute';
    self.options = self.textarea.className;

    self.initialize = function()
    {
        self.editor = self.contentWindow.CodePress;
        self.editor.body = self.contentWindow.document.getElementsByTagName('body')[0];
        self.editor.setCode(self.textarea.value);
        self.setOptions();
        self.editor.syntaxHighlight('init');
        self.textarea.style.display = 'none';
        self.style.position = 'static';
        self.style.visibility = 'visible';
        self.style.display = 'inline';
    }

    self.getCode = function()
    {
        return self.textarea.disabled ? self.editor.getCode() : self.textarea.value;
    }

    return self;
}

1 Answer 1

1
document.getElementById('<%= txtName.ClientID %>').getCode();
Sign up to request clarification or add additional context in comments.

5 Comments

No it's not working. Only ctrl001_txtxName.getCode(); is working fine. Even "ctrl001_txtxName".getCode(); is also not working. Can we not change a string to an object?
or try: <%= txtName.ClientID %>.getCode(); (notice no single quotes)
Thanks "<%= txtName.ClientID %>.getCode();" is working fine but can you tell me what is the exact difference?
'<%= txtName.ClientID %>' will produce a string, <%= txtName.ClientID %> will product an object. which is why i was surprised my original answer did not work.
No worries, glad you got it sorted. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.