相关文章推荐
才高八斗的闹钟  ·  .NETCore Nuget ...·  2 年前    · 
深沉的单杠  ·  How to get only ...·  2 年前    · 
大方的钥匙扣  ·  bash - Adding shell ...·  2 年前    · 

Q&A for Work

Setup a private space for you and your coworkers to ask questions and share information. Learn more about Teams

I have a ascx file in which i am using text box with tinyMCE editor. code is following..

<asp:TextBox ID="txbDiag" TextMode="MultiLine" runat="server" Width="100%" Height="100px"/>
<acr3s:tinymceextender runat="server" ID="TinyMceExtender4" TargetControlID="txbDiag" Theme="Full"/>

like this i have using 5 text box with tinyMCE extender

I am trying to validate my textbox with spacebar, If someone open my page and in text box click on spacebar and click on btn save it should not accept the value and give the error field should not be empty. the code which i use to validate is

if (txbDiag.Text.Trim().Length <= 0)
   msgError.Text =  "<b><font Color=red>*" + "fields are mandatory"+"</font>";
   msgError.Focus();
   return false;

and on btn click i use

txbDiag.Text.Trim();

but while clicking on btn save page is getting saved.

i used the js

<script type="text/javascript">
   function validate(e) {
    var unicode = e.charCode ? e.charCode : e.keyCode;
    if (unicode == 32) {
        return false;
    else {
        return true;
</script>

but this is also not working

I used regular expression and requir field validation that also not causing validation

HOW COULD I VALIDATE MY TEXT BOX FROM SPACEBAR HELP ME????

ah..ok. Why don't you use the functions the tinymce API provides? and btw. the tinymce editor is not inside a textarea - it is inside an own contenteditable iframe – Thariama Jun 28 '11 at 7:31

Ok, first you need to know that tinymce is NOT inside a textbox. Tinymce will create a contenteditable iframe and write back the content to a specified html element (textareas, divs, ps, aso...) from time to time on special events. So grabbing the txbDiag.Text is not very reliable. I suggest you use the tinymce API functions to get the content in order to verify it.

1. to get the right editor use

var my_editor = tinymce.get('txbDiag');

2. get the content

var my_content = my_editor.getContent();

3. Verification of the content: I am not sure what you want to verify exactly! (eighter that a space has been selected, that the content is empty or something else - please describe this EXACTLY)

In case you want to verify if the input is empty you can use

if ($(my_editor.getBody()).text() == '') alert('The input may not be empty!');
                If you have a textbox and in it, you got only spaces then there is no way that .trim() would not work. although, enter the spaces and then look with f.ex. F12 in IE what is the value of the checkbox. perhaps TineMCE changes spaces into &nbsp; ? either way look at the value of the textbox.
                    – ub1k
                Jun 24 '11 at 13:26
if (Textbox1.Text.Replace("&nbsp;", "").Replace("<br />", "").Trim().Length <= 0)
    //Statement here
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

site design / logo © 2019 Stack Exchange Inc; user contributions licensed under cc by-sa 3.0 with attribution required. rev 2019.7.9.34262