Click here to Skip to main content
15,886,079 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My javascript function is following

JavaScript
var txtQuickMailSMS, flag = 0;
function ShowRichTextEditor(id) {
     if (flag == "0") {
         txtQuickMailSMS = new nicEditor({ fullPanel: true }).panelInstance(id);
         flag = 1;
     }
     else {
         txtQuickMailSMS.removeInstance(id);
         flag = 0;
         document.getElementById(id).value = "";
     }
    }


It is for convert multiline textbox like RichTextbox which has all the option like word (bold,italic,bgcolor,textcolor)
It is used page without master page. I call that function in body onload like following
HTML
<body  önload="ShowRichTextEditor('txtRemarks');">


But i want to create that page under masterpage. So in content page there are no master page.
So i give following code in content page pageload event
C#
HtmlGenericControl body = this.Master.FindControl("body") as HtmlGenericControl;
body.Attributes.Add("onload", "ShowRichTextEditor('txtRemarks');");


But it is not working. I give instead of
function to alert function , that is worked. But ShowRichTextEditor is not working.

Any one know the solution to solve this problem, please help me...
Posted
Updated 11-Apr-13 0:33am
v5
Comments
Matej Hlatky 11-Apr-13 6:04am    
What is the exact problem?
Does the element with id txtRemarks exist in output HTML?
When generating elements in ASP.NET, you need to pass ClientID property to your client JS code.

1 solution

Problems in code:-
Why have you written function ShowRichTextEditor(id) two times ?
And there is one closing bracket } which is extra.

Suggestion:-
You can use
1. jshint[^] to find out problems in your code.
2. FireBug Error Console window in Firefox to check all the script and css errors.

Try to make your javaScript code error free and then test.

Solution after discussion with OP
Actually the id will not be the same when you use Master Page.
The id will be no more txtRemarks, there will be one prefix added to this id.
You can check the html in browser.

So, the id will be _________txtRemarks.

For this you have to get the client id of that textbox like below...
<%= txtRemarks.ClientID %>

Else you can make that textbox ClientID Mode static, so that id will not change.

Refer -
1. Control.ClientID Property.
2. How do I pass a server control's actual client Id to a javascript function?.
 
Share this answer
 
v2
Comments
UshaCbe 11-Apr-13 6:32am    
The Bracket is missing When I copied. That's not a problem
Have you used the jslint or Firebug ?
And put a debugger in the function and check what exactly is happening inside the function ?
UshaCbe 11-Apr-13 6:37am    
But it is working with the page is without master page. When I used it inthe content page only that is not working.
Ok, I got you now. Actually the id will not be the same when you use Master Page.
The id will be no more txtRemarks, there will be one prefix added to this id.
You can check the html in browser.

So, the id will be _________txtRemarks.

For this you have to get the client id of that textbox like below...
<%= txtRemarks.ClientID %>

Else you can make that textbox ClientID Mode static, so that id will not change.

Refer -
1. Control.ClientID Property.
2. How do I pass a server control's actual client Id to a javascript function?.
UshaCbe 12-Apr-13 0:50am    
Hi i checked css used with firebug in that Name txtRemarks.ClientID it is working now thank u
And then I set ClientID mode Static also. Then only it is working. Thank u for your kind reply.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900