Google Calendar In Asp.net C# - c#

I want to make event calendar in my web application.
I use this example but it return error wheni i execute it.
http://www.codeproject.com/Articles/201907/Using-Google-Calendar-in-an-ASP-NET-Website
ERROR IS GIVEN BELOW
-----------------------------------------------------------------------------------
Compiler Error Message: CS0103: The name 'GetCalendarID' does not exist in the current context
Source Error:
Line 11: <div>
Line 12:
Line 13: <iframe name="a" src="https://www.Google.com/calendar/embed?src=<%=GetCalendarID()%>&ctz=Europe%2FMoscow"
Line 14: style="border: 0" width="800"
Line 15: height="600" frameborder="0" scrolling="no" id="Test">
-----------------------------------------------------------------------------------
Can any one help me Please?
or if you have better solving then tell me
Regards,
Mehmood Alvi

You're trying to call GetCalendarID() (which would more idiomatically be a property, of course) directly from your page - not on an instance of the GoogleCalendar class. Unless you've added all the GoogleCalendar code from CodeProject directly into your page, you need to first create an instance of GoogleCalendar in your code-behind and provide some way of accessing it, e.g. as a member variable:
<%=calendar.GetCalendarID()%>
Fundamentally, the problem is as simple as the compiler's explained it to be: it can't find a method called GetCalendarID in the context it's got, which is the page. The exact best solution will depend on what else you're doing - the above is just an idea.

You should first call the method SaveCalendarIdAndUrl() cause thats where the m_CalendarId; gets filled before it can be used by the method GetCalendarID()

Related

ASP.NET Getting compiler error message intermittently

I have an aspx page using only inline C# without a codebehind.
Running from Visual Studio it works, however adding the aspx file to the wwwroot of my local machine gives the message
Compiler Error Message: CS1513: } expected
If I rearrange the code to have the method above the code the message is instead
CS1519: Invalid token 'try' in class, struct, or interface member declaration
I expect it is something to do with server configuration, though I don't really know where to start.
The issue only occurs if there is methods, removing method1 from the below results in correct running.
This is the minimum entire file I was able to cause the error with
html
<%# Page Language="C#" %>
<%
try
{
string message = "Text";
Response.Write(method1(message));
}
catch
{
Response.Write("Err");
}
string method1(string source)
{
return source;
}
%>
If you're embedding code directly on the aspx page, that code still has to go in a method. Ex:
<%# Page Language="C#" %>
<%
void Page_Load(Object sender, EventArgs e)
{
try
{
string message = "Text";
Response.Write(method1(message));
}
catch
{
Response.Write("Err");
}
}
string method1(string source)
{
return source;
}
%>
By the way - we don't typically put C# code directly in the .aspx file. That's what the code behind system is for.
And we don't typically write directly to the response. It's hard to control where the markup will end up. In Web Forms, it's better to declare a control on the page and then add markup to that (or show/hide controls). Of course if we're going to talk about doing things well - then don't use Web Forms in the first place. It's a dead technology.
I have messed around with the Visual Studio project, running on an earlier version of .NET/C# yields the following error, It seems possible that this is the actual problem I have had
Error CS8059 Feature 'local functions' is not available in C# 6. Please use language version 7.0 or greater.
I am unsure why it thinks method1 is a local function and details are hard to come by.
Edit: To solve my problem I put the method in script tags instead of embedded code blocks. The methods then could be used from the embedded blocks and the script tag.
<script runat="server">
string method1(string source)
{
return source;
}
<script>

How to use c# singleton class in Orchard Themes

I'm using Orchard to build my website and want to add different elements for production environment and test environemnt in the Themes. I tried to use a c# singleton class in Orchard Themes class to get if it is production environment. Then use the singleton class in the cshtml file in Themes. The code can be compiled. But in run time, it will throw exception saying:The name 'Themes' does not exist in the current context. I have to add "Themes" namespace before the class I added. Otherwise, it won't pass compile.
Details:
I added a singleton class: EnvironmentDev.cs file into Themes.csproj file. It contains static GetInstance method and IsProd property.
In Themes.csproj file, it shows:
<ItemGroup>
<Compile Include="EnvironmentDev.cs" />
</ItemGroup>
In Document.cshtml file of Themes, I added following code:
#{
if (Themes.EnvironmentDev.GetInstance().IsProd) {
// Add production element
}
else {
// Add test site element
}
}
Detailed Error message:
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'Themes' does not exist in the current context
Source Error:
Line 46: #Display(Model.Head)
Line 47: #{
Line 48: if (Themes.EnvironmentDev.GetInstance().IsProd) {
Line 49: <script src="https://XXXX.js"></script> //using XXXX instead of real link
Line 50: }
Any suggestions would be appreciated.
I think you need to create a dedicated project for your theme with the following command
codegen theme MyTheme /CreateProject:true /IncludeInSolution:true
otherwise your code will not be found. I had the same issue with a resource file.
See paragraph Generating the Theme Structure in the docs for further information.

MediaWiki invoke image not working

I'm trying to invoke an image with infobox and infoboxImage. Here is what I have....
|image = {{#invoke:InfoboxImage|InfoboxImage|image={{{image|}}}|size={{{image_size|}}}|upright= {{{image_upright|1}}}|alt={{{alt|}}}}}
And I get the following error on my index.php?title=Module:InfoboxImage&action=submit#mw-ce-l1 page
Script error: Lua error at line 1: unexpected symbol near '|'.
What do I need to do to get this working?
Here is my LocalSettings.php for Scribunto:
require_once "$IP/extensions/Scribunto/Scribunto.php";
#$wgScribuntoDefaultEngine = "luastandalon"';
So you're adding template syntax like {{{image|}}} in a module page? Why?
I doubt you really need to handle such a Lua module for your wiki. However, if you really want to copy the Lua-powered infobox templates of other wikis, make sure you import them with Special:Import and select the recursive import checkbox.
Hopefully you'll then have all the modules you need without fiddling with them.

list problem in c#. how to do this in c#

i have a list of struct
list who have a detail of stuff.
i need a another string info with this list.
so i wrote many function already who is used in my project
so i make a new list
who called stuffdetailedanother
who have a stuffdetailed stuff
and string info;
but when i send it to page using viewdata then he not worked when i use immediate window everything is fine.
are any another way i use ?
or how to pass him to a control
i pass it by a way
controller > View > Partial view
but it is not worked
i got the error
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1519: Invalid token '(' in class, struct, or interface member declaration
Source Error:
Line 347: #line default
Line 348: #line hidden
Line 349: #__w.Write("\r\n </div>\r\n</div>\r\n");
Line 350: }
Line 351:
Source File: c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\2114142c\1d077c0d\App_Web_wishproductlist.ascx.89207646.1grmjmuq.0.cs Line: 349
The problem is that you have a syntax error on line 351 of your ASPX file. Take a closer look at it. If you don't understand why it's not compiling, post the code.
The problem is that the following line:
#__w.Write("\r\n </div>\r\n</div>\r\n");
(Line 349 in App_Web_wishproductlist.ascx.cs) contains a syntax error - probably the # symbol.
Without knowing more context its difficult to know what other advice to give, however hopefully this helps make the error a little clearer.

Issue with GetLocalResource object

I am trying to access my local resources file in my code-behind. I did some googling since I was unsure of how to do it and found this:
oContent.Text = HttpContext.GetLocalResourceObject("NonSupport").ToString();
However, I get an error saying that it needs at least two parameters: VirtualPath and ResourceKey. There is a third, CultureInfo but that one is optional. When I put this in as my virtual path:
HttpContext.GetLocalResourceObject("App_LocalResources/ExpandableListView.aspx.resx", "NonSupport").ToString();
I get the following compiler error message:
The relative virtual path 'App_LocalResources/ExpandableListView.aspx.resx' is not allowed here.
I must be doing something wrong with this since my searches (and some posts I found on here) say all I need to do is call the resource key.
Any thoughts? Thanks!
Did you put a resource file with the name (your aspx web page).aspx.resx into a App_LocalResource folder underneath the path where your ASPX page lives??
Furthermore, just simply call the GetLocalResourceObject method on your current page:
oContent.Text = GetLocalResourceObject("NonSupport").ToString();
No need to use HttpContext for that - the method is defined on the Page class.
Marc

Categories