Sharepoint FormField validation - sharepoint-2010

I have
<SharePoint:FormField
ID="id"
runat="server"
ControlMode="New"
FieldName="FName" >
</SharePoint:FormField>
in the webpart, and a asp.net button on it.
the field is required field. when i click the button the validation does't perform.
how can i validate the field.

It is possible, by calling FormField.Validate(); and FormField.IsValid
But you have to return the outcome of this validation manually to the user. I have not yet found a better solution.

Related

Shopify: How to add user as subscriber from contact form?

I have tried searching but so far haven't been able to find a solution that doesn't involve paying for an app or using a third party form. So if anyone has a solution to this I'd be so happy.
I need to include a checkbox on the standard contact form on a contact page page.contact.liquid. I understand how to add fields, but I want the checkbox, when checked to automatically add the user to our subscriber list.
I have tried adding the below, hidden field, but it doesn't add a subscriber. It doesn't seem to do anything.
<input type="hidden" name="customer[accepts_marketing]" id="hiddenMarketingCheck" autocorrect="off" value="true" >
I did look at the code in the subscriber form section and noticed that the two forms are tagged differently using form_type. So I did some testing and changed the form type from contact to customer. So basically the output goes from this <input type="hidden" name="form_type" value="contact"> to this <input type="hidden" name="form_type" value="customer">.
That 'half works', because it does achieve my original goal to add a user to the 'customer accepts_marketing'. But then it doesn't send the message to the admin user of the site. So now it doesn't work as a contact form.
Does anybody know how I can achieve this? Maybe there are other form types I can use? Or additional fields I need to add?
Any help will be much appreciated.
Many thanks in advance.
My suggestion would be not to add the users at this stage, however, what I did on one of my projects was to put the subscription field AFTER they submitted the contact form and on the success message box.
This way you give them a clear option and understanding that they are subscribing with you and you didn't force them to do so.
I had a much higher acceptance than simply opting in the user.

Using FileUpload in DNN Setting.ascx possible?

first time asking a question here.
I'm making a DNN module and in the Setting.ascx I'm trying to add any form of FileUpload in there. I'm successful at adding ASP's FileUpload as well as Telerik's RadUpload, but when I click a button I added to save and examine the uploaded the file it's empty and no longer holding any data. I thought I was coding it wrong at first, but after adding it into the View.ascx instead it works perfectly. Of course that's not where I want it to be.
I believe the problem might be how the Setting.ascx works in DNN. I believe it's using a form of AJAX to display it so that might be interfering. Hard to say though. While I'm at it can anyone confirm that Setting.ascx is using AJAX and that button clicks cause asynchronous postbacks? Thanks.
You're right with your thought that the form uses AJAX (formerly via UpdatePanel, now via RadAjaxPanel in DNN 6.x), and that's what's interfering with the upload. In most scenarios, you'd just switch to a regular postback by calling ScriptManager.RegisterPostBackControl, but in the settings case, you don't have a direct reference to the LinkButton that saves the settings.
You'll probably need to add your own button to the form to do the upload after the user has selected the file. DNN's own UrlControl uses a system like that, where there's an Upload button next to the Browse button. DNN also has a newer DnnFilePicker control, which might also encapsulate what you want. You'll just need to add an # Register directive to use those. For example:
<%# Reference tagPrefix="dnn" tagName="UrlControl" Src="~/controls/URLControl.ascx" %>
<%# Reference tagPrefix="dnn" Assembly="DotNetNuke.Web" Namespace="DotNetNuke.Web.UI.WebControls" %>
<dnn:UrlControl runat="server" ID="FileUpload"
ShowLog="false"
ShowNewWindow="false"
ShowTrack="false"
ShowImages="false"
ShowNone="false"
ShowTabs="false"
ShowUrls="false"
ShowUsers="false"
ShowFiles="false"
ShowUpLoad="true" />
<dnn:DnnFilePicker runat="server" ID="FilePicker"
FileFilter="jpg,png,gif" />
Man, just don't put a updatepanel outside your ascx control
If you need to use updatepanel, put it inside the ascx. That will resolve your problem!
I was able to solve this problem by doing the following:
Create my own submit button as opposed to relying on the "Save" button built into the page
Adding the following to my LoadSettings() method:
ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(cmdUpload);
Where cmdUpload is the ID of my submit button.
You will need to add a reference to System.Web and System.Web.Extensions for this to compile.

Finding page id of parent form from pop up form

I have two pages
Master page
page using the master page
I am opening a pop up using "window.open" in the second page.
I have textbox control in the second page and trying the find the control in the pop up page using below code.
window.opener.document.getElementById('textbox').value
This code could not found out the control.
Then I checked the page source of second form and dound out the format of control id. It was like below.
"_ctl0_ContentPlaceHolder1_textbox"
and changed the code to below and got success.
"window.opener.document.getElementById('_ctl0_ContentPlaceHolder1_textbox').value"
My query is -> I am not about this approach. Please correct if i am doing anything wrong.
With ASP.NET 4.0 you have the option to set ClientIDMode that could help you in this case.
Setting ClientIDMode to "Static" will ensure that your ID value will not be altered by the framework.
In your page where you have textbox:
<asp:TextBox ID="MyTextBox" runat="server" ClientIDMode="Static" />
Then you should be able to get the value by doing something like this:
window.opener.document.getElementById('textbox').value
Ref: MSDN - ClientIDMode
The problem is that if you use a masterpage the controls of your contentpage will be renamed making it hard to access them from JavaScript.
Use the following code to solve the problem:
<asp:TextBox ID="textbox" runat="server" ClientIDMode="Static"></asp:TextBox>

MonoRail - Server-side vs. Client-side Form Validation

I'm using MonoRail and was wondering how it decides when to use client-side vs. server-side validation? In my model class I have [ValidateNonEmpty] on two properties, one is a textbox, the other is a dropdown. The textbox triggers client-side validation on form submission, if I leave the dropdown empty though it posts back to the server and returns back the validation error from server-side. Is there a way to get the dropdown to trigger client-side validation? Also it's odd because after the postback, it clears what I had entered in the dropdown but maintains the state of the textbox (viewstate anyone??)
Thanks,
Justin
It viewed source and I saw that it was using jQuery for the client-side validation. It had:
"business.businesstype.id":{ required: "This is a required field" },
for the dropdown, which wasn't working. I noticed that it was using 0 as the default dropdown value so I manually put in firstoptionvalue and that got it working:
$FormHelper.Select("business.businesstype.parent.id", $businessTypes, "%{value='id', text='name', firstoption='Select a Business Type', firstoptionvalue=''}")

Custom Code into the Standard DotNetNuke Login?

Where can I find the function that handles the login for DNN? I would like to add custom features to the login and I don't see the function in Login.ascx.vb (unless I missed it).
There is a tag and a tag that forms the login. I figure one of these has the actual "Login" button, but I cannot seem to figure out where they're coming from.
Here is as far as I've found where the login is located
<DNN:DNNTabStrip
ID="tsLogin"
runat="server"
TabRenderMode="All"
CssTabContainer="LoginTabGroup"
CssContentContainer="LoginContainerGroup"
DefaultContainerCssClass="LoginContainer"
DefaultLabel-CssClass="LoginTab"
DefaultLabel-CssClassHover="LoginTabHover"
DefaultLabel-CssClassSelected="LoginTabSelected"
visible="false" />
<asp:Panel ID="pnlLoginContainer" runat="server" style="text-align:left" CssClass="LoginPanel" Visible="false" />
Check out the /desktopmodules/AuthenticationServices directory. The out-of-the-box login control should be coming from DNN/Login.ascx.
You should be able to add user controls to that file.