I am developing a publishing portal in SharePoint. The page layouts, master pages are designed using Visual Studio and I deploy the page layouts into the content database using wspbuilder.
I have a requirement wherein I have to access the controls of the page layout in code behind and assign or get values to/from the controls. But, the VS intellisense never shows the controls used in my page layout. What should I do in order to access the controls using code behind?
Is there any workaround for this?
Regards,
Raghuraman.V
You have to make the web controls on the user control public.
Here's a quick example showing how to change a user control's textbox from the parent page:
WebUserControl1.ascx:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="WebApplication1.WebUserControl1" %>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
WebUserControl1.ascx.cs:
using System;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class WebUserControl1 : System.Web.UI.UserControl
{
public TextBox UserControlTextBox1
{
get { return TextBox1; }
set { TextBox1 = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
WebForm1.aspx:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<%# Register src="WebUserControl1.ascx" tagname="WebUserControl1" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<uc1:WebUserControl1 ID="WebUserControl11" runat="server" />
</div>
</form>
</body>
</html>
WebForm1.aspx.cs:
using System;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
WebUserControl11.UserControlTextBox1.Text = "Your text here...";
}
}
}
I guess that you have the page layouts and the code-behind in two different projects or at least in two different locations. You can also use 'real' code-behind pages in SharePoint that are side-by-side with the ASPX file so that you do not have to re-declare the controls at all.
To do so you can create the Visual Studio project for the WSP package as an
“ASP.NET Web Application”, create ASPX pages with code-behind files side-by-side and use WSP
Builder to remove the C# files from the package (the code is still compiled into the assembly and deploy with it). The trick works because WSP Builder can be
configured with a local configuration file within the Visual Studio project to remove certain file
types.
Here the local WSPBuilder.exe.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Excludefiletypes" value="cs" />
</appSettings>
</configuration>
Related
This code has been working just right in a blazor web assembly, embedded in a razor pages page, using .net 5.0 and .net 6.0.
I had to upgrade to .net 7.0, by altering the framework in razor pages and blazor projects' properties, to fix a big something else and now it doesn't work.
The onclick event is just not being detected.
<p>#(Myawesomevariable)</p>
<button #onclick="Myawesomefunction">Myawesomebutton</button>
#code
{
private int Myawesomevariable = 0;
private void Myawesomefunction()
{
Myawesomevariable++;
}
}
What th' flip?
Okay, you lucky people, here's the fix.
In .net 7.0, first create blazor webassembly solution from the visual studio template, with a client, a server and a shared project.
From the client project, wwwroot folder, delete the index.html file.
From the client project, delete these two lines in the program.cs file:
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
Create a new blazor server project using the visual studio template and copy the _Host.cshtml file from the blazor server project's pages folder, to your project's pages folder and remove the following lines:
<link href="css/site.css" rel="stylesheet" />
<link href="<THE PROJECT NAMESPACE>.styles.css" rel="stylesheet" />
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
and
<script src="_framework/blazor.server.js"></script>
Replacing them with:
<link href="css/app.css" rel="stylesheet" />
<link href="<YOUR PROJECT NAMESPACE>.Client.styles.css" rel="stylesheet" />
<component type="typeof(HeadOutlet)" render-mode="WebAssemblyPrerendered" />
and
<script src="_framework/blazor.webassembly.js"></script>
Create a new razor pages project and copy the following files from the razor pages pages folder to your projects pages folder:
Pages/Shared/_Layout.cshtml
Pages/Shared/_Layout.cshtml.css
Pages/_ViewImports.cshtml
Pages/_ViewStart.cshtml
In the imported _Host.cshtml file, edit the namespace to
#namespace <YOUR PROJECT NAMESPACE>.Server.Pages
and add a reference to the client project
#using <YOUR PROJECT NAMESPACE>.Client
Finally, remove any references to blazor.server.js and make sure every blazor pages calls the blazor.webassembly.js file.
<script src="_framework/blazor.server.js"></script>
I now have a .net 7.0 razor pages project, with blazor components embedded in different pages AND the onclick event handler works.
I have an old application uses wicket 1.4 and want to integrate the liferay reCAPTCHA ( liferay 7.4).
Is there any guide for that?
Or anyone might help ?
It worked for MVC portlet like the following but still cannot achieve same in wicket :
Use CAPTCHA or reCAPTCHA with custom portlet in Liferay MVC Portlet:
CAPTCHA is a “Completely Automated Public Turing test to tell Computers and Humans Apart”. It is used in the computer world to determine whether an end-user is human or non-human. Liferay provides the necessary API as well as tag library to implement CAPTCHA in your custom portlet. Also, you can integrate Google reCAPTCHA in your custom portlet.
Prerequisites
Java
Liferay portal 7/7.x
Use CAPTCHA in custom portlet
Assuming you’ve already created a Liferay-workspace project
Follow below steps to implement CAPTCHA in your custom portlet
Create MVC Portlet
Go to liferay workspace project → modules → new
Select other → Liferay → Liferay Module Project and Click on Next
Enter project name
Select “Project Template Name” as “mvc-portlet” and Click on “Next”
Enter Package name and Click on “Finish”
The necessary file structure for MVC module will get created as below :
2) Now we add below code in view.jsp
<%# include file="/init.jsp" %>
<%# taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %>
<%# taglib uri="http://liferay.com/tld/captcha" prefix="liferay-captcha" %>
<%# page import="com.liferay.portal.kernel.captcha.CaptchaTextException"%>
<portlet:actionURL name="basicFormDataWithCaptcha" var="basicFormDataWithCaptchaAActionURL" />
<portlet:resourceURL id="captcha" var="captchaResourceURL"/>
<liferay-ui:error exception="<%= CaptchaTextException.class %>" message="captcha-verification-failed" />
<aui:form method="post" name="basicForm" action="<%= basicFormDataWithCaptchaAActionURL %>">
<aui:input name="firstName" >
<aui:validator name="alpha"/>
</aui:input>
<aui:input name="lastName" >
<aui:validator name="alpha"/>
</aui:input>
<liferay-captcha:captcha url="<%= captchaResourceURL %>"/>
<aui:button type="submit" value="Submit"></aui:button>
</aui:form>
3) Create Action method in CustomCaptchaPortlet
package ...;
import ...;
#Component(
...
)
public class CustomCaptchaPortlet extends MVCPortlet {
private Log log = LogFactoryUtil.getLog(this.getClass().getName());
#ProcessAction(name = "basicFormDataWithCaptcha")
public void basicFormDataWithCaptcha(ActionRequest actionRequest, ActionResponse actionResponse)
throws IOException, PortletException {
String firstName = ParamUtil.getString(actionRequest,"firstName");
String lastName=ParamUtil.getString(actionRequest,"lastName");
log.info("First Name : " + firstName);
log.info("Last Name : " + lastName);
try{
CaptchaUtil.check(actionRequest);
log.info("CAPTCHA verification successful.");
}catch(Exception exception) {
if(exception instanceof CaptchaTextException) {
SessionErrors.add(actionRequest, exception.getClass(), exception);
log.error("CAPTCHA verification failed.");
}
}
}
#Override
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
throws IOException, PortletException {
try {
CaptchaUtil.serveImage(resourceRequest, resourceResponse);
}catch(Exception exception) {
log.error(exception.getMessage(), exception);
}
}
protected boolean isCheckMethodOnProcessAction() {
return _CHECK_METHOD_ON_PROCESS_ACTION;
}
private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false;}
Output with CAPTCHA
Use Google reCAPTCHA in custom portlet
To integrate Google reCAPTCHA in Liferay please follow below steps
1) Get Site key & Secret key from Google reCAPTCHA
Go to www.google.com/recaptcha in your web browser
Click on “Admin console” button (Located at top-right corner)
Fill up your details in the form and then click on “Submit”
4- You will get “Site key & Secret key” as below image. This you will require while configuring Google reCAPTCHA with Liferay
2) Enable Google reCAPTCHA in your Liferay
Login as admin user
Navigate to Control Panel → System Setting → SECURITY → Security Tools → CAPTCHA
Go to CAPTCHA Engine and change it to reCAPTCHA
Enter “reCAPTCHA public key” and “reCAPTCHA private key”
You need to enter the values you got from Google reCAPTCHA site in previse step , “reCAPTCHA public key” field, and “secret key” in “reCAPTCHA private key” field
Click on ‘Save’
To test Google reCAPTCHA is properly configured or not. Logout from Liferay and go to Create Account page. You can see a default Liferay CAPTCHA is replaced with the new Google reCAPTCHA
3) Use Google reCAPTCHA in your Custom Portlet
Once you configure reCAPTCHA from control panel below, code will render google reCAPTCHA
<liferay-captcha:captcha url="<%= captchaResourceURL %>"/>
If we configure reCAPTCHA from Liferay control panel, Output of above ‘custom-captcha-portlet’ will look like below
As you see it works for MVC portlet but I have some code written in apache wicket which I did not find a way to achieve same and wondering if there is a way to integrate Liferay reCAPTCHA with wicket somehow ?
I would like to create an anonymous page in SharePoint Intranet Site. All rest of the site is using windows claims authentication but I want to create single page which should be anonymous.
I believe there is a way to create a page in IIS under layouts directory and it can be accessible anonymously but I am not able to make it work. Anybody has any idea?
Editing it with the code I have so far
<%# Import Namespace="Microsoft.SharePoint" %>
<%# Page Language="C#" AutoEventWireup="true" Inherits="Microsoft.SharePoint.WebControls.UnsecuredLayoutsPageBase" DynamicMasterPageFile="~/_layouts/15/ErrorV15.master" %>
<HTML>
<script runat="server" language="C#">
protected override bool AllowAnonymousAccess
{ get{ return true; } }
protected override bool AllowNullWeb
{ get { return true; } }
protected void Page_Load(object sender, EventArgs e)
{
}
</script>
<body>
<form id="MyForm" runat="server">
Application page
</form>
</body>
</HTML>
Thanks!
In SharePoint, you shouldn't change any files manually.
You should start with a SharePoint form solution project in your Visual Studio and it will produce a WSP file. By installing it, the SharePoint platform will place it in the correct location (psst, the 15 hive).
In that project, you'll need to add an application page and it needs to inherit from UnsecuredLayoutsPageBase and override the AllowAnonymousAccess property, returning true.
How can i setup kendo ui with mvc4. I want use its themas and grid and all controls in my web application.
I have use http://demos.kendoui.com/themebuilder/web.html but how do i apply generated themas in my website. I am little bit confused with kendo, I am new with it. Please suggest me how can I configure kendo on mvc4 and use its all functionality.
Using : - MVC 4 , html 5 and c#
Thanks!!
How can i setup kendo ui with mvc4
In exactly the same way you would set it up with PHP. Or with a Java Servlet. KendoUI is a client side framework which is server side agnostic. It doesn't matter which server side technology you are using.
I want use its themas and grid and all controls in my web application.
Great, go ahead. Head over to the documentation, read it, roll up your sleeves and integrate into your application.
Create a new ASP.NET MVC 4 application using the Empty template
Add a HomeController to serve up a view:
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
}
And of course a corresponding ~/Views/Home/Index.cshtml view:
#{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<link rel="stylesheet" href="//cdn.kendostatic.com/2012.2.710/styles/kendo.common.min.css" />
<link rel="stylesheet" href="//cdn.kendostatic.com/2012.2.710/styles/kendo.default.min.css" />
</head>
<body>
<input id="dropDownList" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="//cdn.kendostatic.com/2012.2.710/js/kendo.all.min.js"></script>
<script type="text/javascript">
$("#dropDownList").kendoDropDownList({
dataTextField: "text",
dataValueField: "value",
dataSource: [
{ text: "Item1", value: "1" },
{ text: "Item2", value: "2" }
]
});
</script>
</body>
</html>
As you can see there's absolutely nothing MVC specific here. You could have served this markup from any server side framework. All you need is pick a theme, reference it from the Kendo CDN, reference the Kendo scripts at the end of your DOM from the CDN and start playing with it.
But the most important thing if you want to have some progress is to RTFM where the guys from Telerik (and colleagues of mine) have spent a lot of time to documenting everything you need to know.
There is a tutorial on the Kendo Docs site that will walk you through it step by step.
Hello Kendo UI - Add Kendo UI
and
Kendo Music Store - Project Setup
I am looking to create a page with a single form on it that does the following:
Contact a webservice with input from the form.
Perform an action (programmed using C#) depending on the result of the webservice call.
Since I am not interacting with any lists or similar on the SharePoint site, I was thinking a WebPart would be the simplest way to add the form and catch the submit-event, but I am not sure if this is the best practice or an easier/better way exists.
I also need to restrict access to the form to a specific usergroup.
Thanks in advance!
A new SharePoint Web Part is probably the most common way to provide this solution in SharePoint and fits your requirements well. Though your solution doesn't call for it, you do have access to the lists from custom web part code.
If you are using SharePoint 2007, Visual Studio Extensions provide the Microsoft supported way to create one easily. It's much easier with Visual Studio 2010 and SharePoint 2010.
Some other options would be an InfoPath Form with custom code or a custom application page with code behind. The benefit of the web part is that it works with all versions of SharePoint and can be added to any web part page on the site and customized by users. Also, the application page may not pick up the master page if you are on SharePoint 2007.
Use WebDAV to upload an ASPX page to a site in SharePoint. Then upload your assembly to each SharePoint server, the bin folder of your application is preferred, or add it to the GAC.
Your ASPX page might look like this:
<%# Page Language="C#" masterpagefile="~masterurl/custom.master" inherits="MyAssembly, MyClass, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c48b11b32c9eb4a7" %>
<asp:Content runat="server" ContentPlaceholderID="PlaceHolderPageTitle">My Title</asp:Content>
<asp:Content runat="server" ContentPlaceholderID="PlaceHolderPageTitleInTitleArea">My Page</asp:Content>
<asp:Content runat="server" ContentPlaceholderID="PlaceHolderMain">
<asp:Button runat="server" ID="ButtonClickMe" Text="Click Me!" />
</asp:Content>
Then your assembly might look something like this:
public class MyClass : Microsoft.SharePoint.WebPartPages.WebPartPage
{
protected global::System.Web.UI.WebControls.Button ButtonClickMe;
protected override void OnLoad(EventArgs e)
{
base.OnLoad( e );
ButtonClickMe.Click += new EventHandler( ButtonClickMe_Click );
}
void ButtonClickMe_Click(object sender, EventArgs e)
{
if (!Page.IsValid)
return;
// Do stuff here
}
}
You won't be able to edit the permissions of the ASPX page directly, but you can manipulate the permissions of the site it is in (thus, restrict the site to only the usergroup which you want to access the form).