Display simple c# in "sharepoint online" - c#

I am using "SharePoint Online" and I'm new to it. I have descend programming background and I need more Info on customisation of this service. I've never worked with .NET before (WHAT?!), but I would really like to learn more about C# and it's use in the industry. I have full access to SharePoint Designer and I have Visual Studio 2008.
1) How can I implement simple c# code on SharePoint web page?
2) How to import and use c# classes on SharePoint page?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%# Page Language="C#" %>
<%# Register tagprefix="SharePoint" namespace="Microsoft.SharePoint.WebControls" assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta name="WebPartPageExpansion" content="full" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 4</title>
<meta http-equiv="X-UA-Compatible" content="IE=10" />
<SharePoint:CssRegistration Name="default" runat="server"/>
</head>
<body>
<form id="form1" runat="server">
</form>
</body>
</html>
This is a brand new, empty .ASPX page generated by "SharePoint Designer". How can I import and display simple "Hello World", c# code on it?
Thank you very much in advance

Inside your <form> tag, insert this line:
<form id="form1" runat="server">
<% Response.Write("Hello World"); %>
</form>
Have fun learning C#

You cannot run server-side scripts on your ASP.NET pages in SharePoint online. It is not allowed and will tell you as much when you try to do this.
If you had an on-premises site, you could modify a setting in web.config to enable this, but that is beside the point.

Related

What do I have to do to get my ASP.NET MasterPage to work on my server?

I followed some examples in my ASP.NET 4.5 in C# book for Master Pages. So I made a more complex site using them, and it all works locally. But when I push it to my remote server, it is saying the file cannot be found. So I made a more basic master page in Visual Studio 2015 to check. And it works locally, but when pushed to the remote server, it still does not work. I couldn't find any answers online either. I've tried some different urls thinking I was using the wrong url too. I've used
myWebSite.com/TestFolder/MasterPage.master
myWebSite.com/TestFolder/
myWebSite.com/TestFolder/MasterPage
So I'm not sure what I'm doing wrong. Any help would be greatly appreciated.
The code for my master page looks like this:
<%# Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Tester</title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<h1>This is a test of the master page.</h1>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
I fixed it. I made sure that the file path to the CodeFile in the header was "./MasterPage.master.cs" and the MasterPageFile reference in the header of the content page was "./MasterPage.master" not "~/MasterPage.master".
The url also worked just as myWebSite.com/
Thank you for the help anyways. Much appreciated.

Obfuscate aspx pages - c# codes are inside aspx files

Please take a look at this link :
http://forums.asp.net - Obfuscate aspx pages
I have the same problem and my problem is how can i obfuscate aspx pages with c# codes inside?
I know for .net dlls we can use :
Dotfuscator
Or
Other third party programs...
But what about aspx files with c# codes and my purpose is to obfuscate c# method names and strings in that file!
EDIT :
My aspx file is like this :
<%# Page Language="C#" Debug="true" trace="false" validateRequest="false" EnableViewStateMac="false" EnableViewState="true"%>
<%# import Namespace="System.IO"%>
....
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
C# Codes...
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title></title>
<style type="text/css">
...
</style>
<script type="text/javascript">
...
</script>
</head>
<body>
<form id="" runat="server">
...
</form>
</body>
</html>
obfuscation of aspx(html) part is not important for me and only want to obfuscate C# Codes...
Edit 2 :
What is your purpose?
Are you crazy?
No, i'm not.
sometimes i don't have access to Visual Studio and want to write a little project very quickly in a single file with c# codes and gave it to my customer.
Based on what you said, "how can i obfuscate such these files (aspx codes + c# codes in one file)?" You cannot do that. You can use the Code-Behind Model which is where you C# code in a separate file.
Code-Behind
Code-behind refers to code for your ASP.NET page that is contained
within a separate class file. This allows a clean separation of your
HTML from your presentation logic.

No value field in DropDownCheckBoxList in project created from scratch, but present in download package project

I've downloaded DropDownCheckBoxList control from it's official page.
I've created new WebSite inside Visual Studio 2012 using File -> New -> WebSite and I added dll into references.
Then inside Default.aspx I've added this sample code:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%# Register TagPrefix="asp" Namespace="Saplin.Controls" Assembly="DropDownCheckBoxes" %>
<!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>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> </script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownCheckBoxes ID="checkBoxes2" runat="server">
<Style SelectBoxWidth="300" />
<Items>
<asp:ListItem Text="Option 1" Value="1" />
<asp:ListItem Text="Option 2" Value="2" />
</Items>
</asp:DropDownCheckBoxes>
</div>
</form>
</body>
</html>
After starting debugger my web site is displayed, but when using element inspector in Chrome I noticed that DropDownCheckBoxes isn't rendering value field for checkboxes:
Inside download package that comes with DropDownCheckBoxList is sample project, when I start it I can see that value field is rendered:
It's my fourth hour trying to figure out what is wrong with my code!
How should I create WebSite or WebApplication to have value field rendered?
After another 4 hour searching over SO I found awesome answer:
https://stackoverflow.com/a/15030781/965722
When below entry is added into web.config value isn't rendered
<pages controlRenderingCompatibilityVersion="3.5">
So removing it instantly solved my problems.

Update panel causes JavaScript error

I am facing this issue in my asp.net application when using update panel. The error only with IE9 and for other browser application works fine. For debuging purpose and to conclude the issue only when using update panel I created a sample asp.net web site.
ASPX
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager runat="server" />
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Button ID="Button1" Text="Click Me" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
When I click on the button, I get the following JS error.
The JS error is
From IE's F12 developer tool,
SCRIPT5007: Unable to get value of the property 'tagName': object is null or undefined
frameTracker.js, line 2 character 395
From Visual Studio 2012,
But when I remove the update panel, the JS error is no longer.
Any idea to solve this problem?
Add following line in <head>
<meta http-equiv="X-UA-Compatible" content="IE=8;FF=3;OtherUA=4" />
OR
<meta http-equiv="X-UA-Compatible" content="IE=9;FF=3;OtherUA=4" />
OR
<meta http-equiv="X-UA-Compatible" content="IE=Edge" /> // is will always be rendered in IE's latest and greatest mode

Javascript Unable to GetElementById in ASP.NET C#

I know this is a very common problem. I was trying to get a "enter key" event to invoke a click on a certain button on the page through javascript. However, I can't for the life of me fetch a single element by its id or name from my asp.net page.
It is my understanding that this issue is related to where the javascript is located and whether the elements have been rendered by the time the javascript is loaded or something of that nature?
Every time I attempt to use var x = document.getElementById('btn_AddAdmin') I end up with a null value.
My asp.net page has SiteMaster page that it inherits from. I have included a trimmed down version of my asp.net page and the SiteMaster page.
ASP.NET Page:
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master"
AutoEventWireup="true" CodeBehind="Admin.aspx.cs" Inherits="HERMES.Admin" %>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<input type="text" id="txt_AddAdmin" runat="server" onkeypress="Populate()" />
Master Page:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs"
Inherits="HERMES.SiteMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
<title></title>
<link href="./Styles/Site.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form runat="server">
</form>
</body>
Sorry for the formatting, I seem to be doing something wrong...
I have attempted placing the javascript in many different locations -- anywhere from the sitemaster page to the top and bottom of my asp.net page. No luck either way.
var x = document.getElementById('<%= btn_AddAdmin.ClientID %>');
If your button is a Server Control it prepends a naming scheme to the input button so it can be bound back to the appropriate server control during postback. Thus the need to use the ClientID property to retrieve the "rendered id".
To learn more visit:
http://www.asp.net/web-forms/overview/client-script,-jquery,-and-ajax
http://www.asp.net/
Google it with Bing:
clientid
aspnet webforms client side programming

Categories