Custom DotNetNuke module development form validation - c#

I am using the Module Creator module within DotNetNuke to create a very basic contact form. The form works as intended, but I'm having trouble with the validation.
When one submits the form without properly filling out the required fields, it invokes the form validation and displays the appropriate error messages. However, if I'm not trying to fill out the form and instead am selecting admin features of DotNetNuke to administer the site, the form validation for my custom module fires and prevents me from using the core functionality...
How do I prevent my form from being submitted when DotNetNuke admin functionality is what is being clicked?
Thanks for any help provided.

Solution is ValidationGroup
Use the validationgroup on your controls that has to be checked and at the validationgroup to your button.
Control with Requiredfieldvalidator:
<asp:textbox id="tbName" runat="Server"/>
<asp:requiredfieldvalidator id="rfvName" controltovalidate="tbName" validationgroup="Save" errormessage="Enter your name."
runat="Server"/>
Button:
<asp:LinkButton ID="lbSave" ValidationGroup="Save" resourcekey="cmdAdd" runat="server" class="dnnPrimaryAction" OnClick="Onclick_lbSave" /></li>

Thank you JK84! The use of ValidationGroup on my required field validators did the trick.

Related

How to handle two different forms in an asp.net web page?

I have a login page in my asp.net website (using C#) and it has a "login form" which has an email text box, a password text box and a login button.
In addition, I have a "search form" at the top of the web page which has a search text box and a search button.
*All of the controls are in the same form because of the asp.net limit for one runat="server" form.
The problem is that when I type something to search for and click ENTER (and not directly the button) it doesn't do anything, only runs the Page_Load again. Same thing when I click ENTER in the login section instead of directly on the login button.
I have tried different solutions but they were problematic because of the different functionality of the two "forms".
I have no idea how to solve this, any suggestions?
my web forms is a little rusty but I think something like this:
<asp:Panel ID="loginPanel" runat="server" DefaultButton="loginButton">
<%-- Login Stuff--%>
<asp:Button ID="loginButton" runat="server" />
</asp:Panel>
<asp:Panel ID="loginPanel" runat="server" DefaultButton="searchButton">
<%-- Search Stuff --%>
<asp:Button ID="searchButton" runat="server" />
</asp:Panel>
should work
Only one form with runat='server' available on aspx page. So, if you really need another form, you may use its without runat='server' and use for search jQuery ajax call.

Multiple forms on page asp.net

I have a problem with multiple forms on my asp.net website. On the Master page i have a small form for every page and on some pages i also want to have a form. I know it is not possible to have for form tags with runat=server, so i am searching for a solution.
Is it possible to deactivate the validators from one of the forms, so the other form can pass? Then i could manage the 2 forms together in the server-side c# code.
Is this possible or are there any other solutions u know?
you can give your validation control a group name like
<asp:RequiredFieldValidator ControlToValidate="TextBox2" ValidationGroup="Login" ID="RequiredFieldValidator2" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
and use that group name to the button you want to validate on click like
<asp:Button ID="Button1" runat="server" Text="Login" ValidationGroup="Login" />

Unblock controls if !Page.IsValid

I have ASP.NET WebForms application. One of it's pages is dynamically created table with RegularExpressionValidator. Above of table there are several LinkButtons, which manages navigation of application. But if I put invalid value to textbox in table, Page.IsValid is set to false and all controls on page are blocked.
So, how can I unblock buttons even if validator set Page.IsValid to false? Thnak you.
You could use ValidatorGroups to separate the validations.
Assuming you want to "unblock" the link buttons used for navigation, you can use:
CausesValidation="False"
in the ASPX markup for the link button.
Example:
<asp:LinkButton ID="btnBack" runat="server" data-transition="fade" CausesValidation="false"
data-theme="b" data-icon="" Text="Back" onclick="btnBack_Click" />

Required Field Validator for login page in asp.net

I'm working on the login in one of my asp.net project.
I have completed the login page but facing problem when I have included asp.net validation.
I have inserted required field validator for the username and password textbox in my login page,I have link for new user registration and also forget password.
My problem is, eventhough I want to click new user or forget password link, required field validator for textbox and username shows error message.
You need to use ValidationGroup Property to fix this.
ex:
<asp:textbox id="tb1" runat=Server />
<asp:requiredfieldvalidator id="ReqField1" controltovalidate="tb1"
validationgroup="valGroup1" errormessage="Required" runat=Server />
<asp:ImageButton id="Button2" causesvalidation=true
validationgroup="valGroup2" ImageUrl="img.gif" runat=Server />
Or Else
Assign CauseValidation="False" in New registration and Forget Password Button to fix
Add CausesValidation="false" to the links that should not trigger validation.
change the validation group of these two linkbuttons (forget password, New user linkbuttons) to be not the same of the login button control and I hope your problem will be solved :)..

.NET two "forms" on a page and their validators

I have got a page that has 2 "forms" (What I mean by a form here is a Panel consisting of: textboxes, validators and a button).
(I got 2 here because one of them is actually on the MasterPage, shown all the time)
The problem is when you try to submit to one of the form, it will validate the other form, which of course is blank and invalid.
How do you solve this problem?
Thank you.
Your problem can be solved with asp.net ValidationGroups.
http://weblogs.asp.net/scottgu/archive/2004/10/24/246945.aspx
Basically, you group the controls to be validated using a uniquely named validation group. Like so:
<asp:Textbox ID="txt" runat="server" />
<asp:RequiredFieldValidator id="rfv" runat="server" ControlToValidate="txt" ValidationGroup="masterGroup">* Required!</asp:RequiredFieldValidator>
<br />
<asp:Button id="btnSubmitMaster" runat="server" Text="Submit!" ValidationGroup="masterGroup" />
If you group your inputs like this, then assign the validation group to the control that submits the form, the inputs in the other validation groups won't be validated.

Categories