Design and CSS styles
Version 7.x > Design and CSS styles > Unable to save page content when content contain asp:RequiredFieldValidator View modes: 
User avatar
Member
Member
gianglt3-fsoft.com - 10/23/2013 2:36:53 AM
   
Unable to save page content when content contain asp:RequiredFieldValidator
Hi all!
I have a page contain textbox and asp:RequiredFieldValidator for this textbox so when i change content this page, RequiredFieldValidator still validate and require me input to this textbox before save.

I try with:
xxcontrol.CausesValidation = false
and
Page.EnableEventValidation
but not work for me.

Could you tell me a suggest, please!!

User avatar
Kentico Support
Kentico Support
kentico_romank - 10/23/2013 3:49:20 AM
   
RE:Unable to save page content when content contain asp:RequiredFieldValidator
Hi,

Lets say you have a textbox and button on your page with the code:
<asp:TextBox runat="server" ID="myText" />

<asp:RequiredFieldValidator runat="server" ControlToValidate="myText" ID="searchValidate" ErrorMessage="Search box is empty!" />

<asp:Button runat="server" ID="submit" />

All you have to do to make it work is to add these elemets to some validation group, for example like this:
<asp:TextBox runat="server" ID="myText" />

<asp:RequiredFieldValidator ValidationGroup="login" runat="server" ControlToValidate="myText" ID="searchValidate" ErrorMessage="Search box is empty!" />

<asp:Button ValidationGroup="login" runat="server" ID="submit" />


Best Regards,
Roman Konicek

User avatar
Member
Member
gianglt3-fsoft.com - 10/23/2013 5:21:16 AM
   
RE:Unable to save page content when content contain asp:RequiredFieldValidator
Thank Romank for replying me!
i think your suggest is good idea,so i tried this solution,but it's not working for me.

User avatar
Kentico Support
Kentico Support
kentico_romank - 10/23/2013 5:36:36 AM
   
RE:Unable to save page content when content contain asp:RequiredFieldValidator
Hi,

When you said "it is not working", what do you exactly mean? Do you get any error message or the behaviour is just same as before?

Also could you please post the code we are talking about? I would like to inspect it.

Best Regards,
Roman Konicek

User avatar
Member
Member
gianglt3-fsoft.com - 10/23/2013 5:42:01 AM
   
RE:Unable to save page content when content contain asp:RequiredFieldValidator
Thank you!
My code same your suggest:
<asp:TextBox runat="server" ID="myText" />

<asp:RequiredFieldValidator ValidationGroup="login" runat="server" ControlToValidate="myText" ID="searchValidate" ErrorMessage="Search box is empty!" />

<asp:Button ValidationGroup="login" runat="server" ID="submit" />


but when i edit content and click save,page still require me input to textbox.

User avatar
Kentico Support
Kentico Support
kentico_romank - 10/24/2013 4:10:30 AM
   
RE:Unable to save page content when content contain asp:RequiredFieldValidator
Hi,

Could you please tell me, where exactly did you put this code? Did you insert this code to the layout of the page template or some place different?

Also when you said "when I edit content", you mean that you have a text editable web part on the page and you modify the content of this web part, is that correct?

Best Regards,
Roman Konicek

User avatar
Member
Member
gianglt3-fsoft.com - 10/24/2013 4:40:45 AM
   
RE:Unable to save page content when content contain asp:RequiredFieldValidator
Code in my webpart :
<div class="box_650 left margin-top30">
<ul class="listcontact">
<cms:CMSEditableRegion runat="server" ID="ContactUsRegion" RegionType="HtmlEditor" RegionTitle="Contact Us Region" DialogHeight="200" DialogWidth="500" />
<li class="margin-top30">
<label class="rowa"> </label>
<label class="rowb">
<span style="font-weight: bold;color:#3081EE; font-size: large;">
<asp:Label ID="LblMessage" runat="server"></asp:Label></span>
</label>
</li>
<li>
<label class="rowa">Name</label>
<label class="rowb">
<asp:TextBox runat="server" ValidationGroup="ContactUs" ID="TxtName" MaxLength="24" CssClass="input200" />
<asp:RequiredFieldValidator ValidationGroup="ContactUs" ID="RequiredFieldValidator1" runat="server" ControlToValidate="TxtName" Display="None" SetFocusOnError="True"></asp:RequiredFieldValidator>
</label>
</li>
<li>
<label class="rowa">Email Address</label>
<label class="rowb">
<asp:TextBox runat="server" ValidationGroup="ContactUs" ID="TxtEmail" MaxLength="100" CssClass="input200"></asp:TextBox>
<asp:RequiredFieldValidator ValidationGroup="ContactUs" ID="RequiredFieldValidator4" runat="server" ControlToValidate="TxtEmail" Display="None" SetFocusOnError="True"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ValidationGroup="ContactUs" ID="RegularExpressionValidator6" runat="server" ControlToValidate="TxtEmail" Display="None" ValidationExpression="^(([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+([;.](([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+)*$" SetFocusOnError="True"></asp:RegularExpressionValidator>
</label>
</li>
<li>
<label class="rowa"> </label>
<label class="rowb">
<asp:Button ID="BtnSend" ValidationGroup="ContactUs" runat="server" CssClass="button_send" OnClick="BtnSend_Click" />
</label>
</li>
</ul>
</div>

My page have 2 zone (header zone and left zone) and i drag this webpart to left zone

Also when you said "when I edit content", you mean that you have a text editable web part on the page and you modify the content of this web part, is that correct?

It's correct.When i modify the content of Editabletext "ContactUsRegion" finish then i click save but page show error on 2 textbox (TxtName,TxtEmail).

Best Regards,
Giang.

User avatar
Kentico Support
Kentico Support
kentico_romank - 10/29/2013 3:27:25 PM
   
RE:Unable to save page content when content contain asp:RequiredFieldValidator
Hi,

I havent been able to reproduce this issue. I have created custom web part, then I put the code you have posted in it.

After that I have placed web part on some page and try to insert text to "Contact us region" and save it, that went well, without any issues.

Are you still experiencing the issue? If yes, could you please export me that web part you are using and send it to support@kentico.com (please refer to this forum thread), please attach also screenshot of Design and Page tab in CSM Desk.

Best Regards,
Roman Konicek

User avatar
Member
Member
gianglt3-fsoft.com - 10/30/2013 1:45:45 AM
   
RE:Unable to save page content when content contain asp:RequiredFieldValidator
Thank you for reproduce this issue for me!
I found out what was wrong,i added a method to javascrip to custom validate(high light textbox when error)
function ValidatorUpdateDisplay(val){....}

this is link refer :http://blogs.msdn.com/b/valdon/archive/2010/02/11/customizing-asp-net-validators-without-using-the-customvalidator-control.aspx
if i remove this function,it's working well.

So,i have a question is how i detect this page is CMS desk page or Live page in JavaScript
to i'll modify function ValidatorUpdateDisplay
function ValidatorUpdateDisplay(val){
if(!isCMSDesk)
{....}
}


ps:function ValidatorUpdateDisplay in file .js so CMSContext.ViewMode is unusable
thank and best-regards!
Giang

User avatar
Kentico Support
Kentico Support
kentico_romank - 11/12/2013 5:53:10 AM
   
RE:Unable to save page content when content contain asp:RequiredFieldValidator
Hi,

I found that you asked similar question in past http://devnet.kentico.com/Forums.aspx?forumid=65&threadid=41505. This approach didnt work for your?

Another approach could be to use for example some static web part with div HTML tag, where you set some ID, then you will set visibility condition of the web part {%PortalContext.ViewMode == "edit"%}.

Then you will be able to decide if you view the site in CMS Desk or on live site by checking if the div ID exists on the live site by javascript function getElementById("test_div").

I hope this information helps.

Best Regards,
Roman Konicek

User avatar
Member
Member
gianglt3-fsoft.com - 11/12/2013 8:09:58 PM
   
RE:Unable to save page content when content contain asp:RequiredFieldValidator
Thank you very much!

Best Regards,
GiangLT3