I have the following class...
public class MyCustomLogger
{
public static int DEFAULT_INFO = 0;
public static int DEFAULT_LOGIN = 1;
//etc
public static void Log( ... )
{
doStuff(...);
}
public static void Log( ... , ... )
{
doStuff(...);
}
private static void doStuff(...)
{
//doLots of Stuff
}
So when I call MyCustomLogger.Log(...); from another Custom Class... it works fine. No compile errors...nothing. It just works
When I call it from SuchAndSuch.master code behind... it works fine. No Compile errors...nothing. It just works.
When I call it from SuchAndSuch.ascx code behind... it works fine. No Compile errors...nothing. It just works.
However... when I call it from SuchAndSuch.aspx code behind... it doesn't work. I'm getting 'MyCustomLogger' does not contain a definition for 'Log'
I'm getting this from any aspx page I add it to.
EDIT
Here's a snippet from the aspx pages i'm trying to add it to
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Logout : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//doStuff
}
protected void Button1_Click(object sender, EventArgs e)
{
MyCustomLogger.Log(MyCustomLogger.DEFAULT_INFO);
Has anyone else experienced this?
Here are a few ideas on what might be causing this:
If this is a web site project, which I'm guessing because your extract does not include a namespace, do you have another class in your app_code folder with the MyCustomLogger name?
If this page is in the Master Page, is the Master Page exposing something named MyCustomLogger as a public property and conflicting with the app_code definition?
If this is a web application project, the problem could be because the Namespace declaration is missing on the page.
Is there another type in the page that's MyCustomLogger that there is a conflict (can't resolve the correct type? Can you post any code to help us see the issue?
Related
I'm need to run my old project using ASP.NET webform with .NetFramework 3.5
So. I'm facing with problem missing ajaxpro javascript file (error 404) when I run test
Here is code I register Ajaxpro class
public partial class WebPage_Event_Event : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
pmSetClientAttributesControls();
}
}
private void pmSetClientAttributesControls()
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(WebPage_Event_Event));
}
[AjaxPro.AjaxMethod]
public bool Ajax_pmChkTimeOut()
{
return System.Web.HttpContext.Current.Session["Login"] == null;
}
}
So. when I run on IIS express in VS2022 I found this error
Any one know how to fixed this
Thank you.
I have a winform app, I completed with business model and update function. But when I learn about security .Net, I found that almost impossible to anti crack/hacking with obfuscation.
So I want move 99.99% source code to cloud. But I've not found any doc that useful for making it.
Can I do my idea as below:
using ....;
namespace myApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public GetSourceClass()
{
// Here i want get all source code, include all class and all
// variables from server.Is it possible?
}
private void Form1_Load(object sender, EventArgs e)
{
GetSourceClass();
}
I am loading a .NET application using the ICLRRuntimeHost::ExecuteInDefaultAppDomain method which starts the application up fine. However, the application is using Log4Net with which it should output an info message after starting up, but it never does. It works fine when opening it up normally though, so it must be something with the CLR Hosting environment that makes it unable to function properly, I just don't know what exactly.
Here is the code that does the logging:
using System;
using System.Windows.Forms;
using log4net;
namespace TestApplication
{
public partial class MainForm : Form
{
private static readonly ILog log = LogManager.GetLogger
(MethodBase.GetCurrentMethod().DeclaringType);
public MainForm()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
log.Info("Application has started");
}
}
}
So this is the very first time I try to create a custom renderer. I followed this thread here: https://forums.xamarin.com/discussion/32264/how-can-i-change-switch-text-color-android. I took a look at the first guy who placed an example code. I tried to use it with my own renderer but It gives the following error:
Type or namespace 'controls' doesn't exist in 'saleskicker'
here is my code:
using System;
using Xamarin.Forms.Platform.Android;
using Xamarin.Forms;
using SalesKicker;
[assembly:ExportRenderer(typeof(SalesKicker.Controls.CustomSwitch), typeof(CustomSwitchRenderer))]
namespace SalesKicker
{
public class CustomSwitchRenderer : SwitchRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Switch> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.TextOn = "AAN";
Control.TextOff = "UIT";
Control.SetTextColor(Color.White);
}
if (Control.Checked == true)
{
Control.SetBackgroundColor(Color.Green);
}
}
}
}
However, the error didn't show up when I had the class inside a folder called 'CustomRenderers'. But I think this shouldn't be such a big deal. What am I doing wrong here? Can someone please help me?
If you just want to change the Color, you don't need a CustomControl. And then you can replace the default renderer with your own.
[assembly:ExportRenderer(typeof(Switch), typeof(CustomSwitchRenderer))]
I have something like this in Site.Master in an asp.net mvc3 (not razor) project:
<telerik:RadRibbonBar ID="RadRibbonBar1" runat="server">
The code behind is defined as such:
<%# Master Language="C#" Inherits="myproject.Site_Master" CodeFile="Site.Master.cs" %>
So Site.Master.cs is:
using System.Web.Mvc;
using System;
namespace myproject
{
public partial class Site_Master : ViewMasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
How can I access radribbonbar1 from Page_loaded (which does get called once the page loads).
I was under the impression by giving it an ID it would be autogenerated to be accessible via C# code but that isn't happening (there is no variable radribbonbar1 available to Site_master).
Any ideas for how to make this work?
Server controls will not work properly because they require event handling, which you do not have in ASP.NET MVC. See the jQuery ribbon plugin
Didn't test this with your example but something like this might work
public static Control FindControlRecursive(Control root, string id)
{
return root.ID == id ? root : (from Control c in root.Controls select FindControlRecursive(c, id)).FirstOrDefault(t => t != null);
}
And, in your page_load
RadRibbonBar radRibbonBar1 = (RadRibbonBar)FindControlRecursive(Page, "RadRibbonBar1");