I have a trouble with ASP.NET validations. At first my validation worked successfully. But when I began routing, my client-side validations stopped working.
My problem is it deals with braces.
There is successful and unsuccessfull codes:
Successful example
void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.Add("Pages", new Route("{PageName}/", new PageRouteHandler("~/Page.aspx")));
}
Unsuccessful example
void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.Add("Pages", new Route("PageName/", new PageRouteHandler("~/Page.aspx")));
}
How can I overcome this problem?
Related
We have ASP.NET application with Global.asax.cs file where we use application event handlers as following:
protected void Application_Start(object sender, EventArgs e)
{
log.Info("The App started.");
}
protected void Application_End(object sender, EventArgs e)
{
log.Info("The App finished.");
}
We want to use OWIN now, which means adding Startup.cs file. Is there any way to move handlers from Global.asax.cs то Startup.cs file or something else where we can put our logs?
OwinContext in Startup.Configuration() is different from the traditional ASP.NET HttpContext which exists in MvcApplication.Application_Start(). Both are using different pipelines.
And because of that you can't use MvcApplication.Application_Start() in Startup.Configuration()
I have a trouble with asp.net validations. At first my validation worked successfully. But when I began to routing, my clientside validations didn't work. There is successful and unsuccessfull codes:
Unsuccessful example :
void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.Add("Pages", new Route("{PageName}/", new PageRouteHandler("~/Page.aspx")));
}
Successful example :
void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.Add("Pages", new Route("PageName/", new PageRouteHandler("~/Page.aspx")));
}
How can I overcome this problem?
In my website I wrote that code:
protected void Page_Load(object sender, EventArgs e){ LinkButton lbtnTopicAddress = new LinkButton(); lbtnTopicAddress.Click += lbtnSpecificTopic1_Click;}
protected void lbtnSpecificTopic1_Click(object sender, EventArgs e){ Server.Transfer("~/SpecificTopic.aspx)"
}
But when I press on the link in run time, the caller doesn't go to the EventHandler method.
Why?
Note,
I wrote code like that in many pages in the same website but it work only in one page.
i added that code to many page in website but it worded only in one page every page has its specific code and no relation between them I hope you understand me thanks
I need help pleaseeeeeeee..........................
Did you mean to miss off a ;and a } here?
protected void lbtnSpecificTopic1_Click(object sender, EventArgs e){ Server.Transfer("~/SpecificTopic.aspx)"
I assume you've put a breakpoint in to ensure it isn't being fired?
I'm not exactly sure but I've got a feeling that instead of Page_Load you need to use Page_Init so your code would look this this:
protected void Page_Init(object sender, EventArgs e)
{
LinkButton lbtnTopicAddress = new LinkButton();
lbtnTopicAddress.Click += lbtnSpecificTopic1_Click;
}
protected void lbtnSpecificTopic1_Click(object sender, EventArgs e)
{
Server.Transfer("~/SpecificTopic.aspx");
}
p.s. 5 mins formatting your code can work wonders when trying to debug
Are you adding the button to the controls on your page, or are you trying to find the "lbtnTopicAddress" control on your page?
Simply declaring the button won't do anything -- you have to get a reference to the control itself from the page.
I have objectdatasource and I am trying to find a way to capture the error that is thrown by the SELECT method.
anyone idea how it can be done?
Page level error handling is preferred, not capturing error at the application_error in global.asax
thanks,
Like this:
protected void Page_Load(object sender, EventArgs e)
{
ds.Selected += new ObjectDataSourceStatusEventHandler(ds_Selected);
}
void ds_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
if (e.Exception != null)
{
}
}
I have an asp.net website and i want to get the number of users currently viewing my site. I am aware that there are some third party softwares available, that would give me the list of the users online but i don't want to do that.
Does anyone know how this can be achieved in asp.net? May be if there are any server variables that would keep a track of the website instances that gives the number of users currently visiting the site. Please help me.
if you want to count users which are using your website at the moment you can use the following code in your global.asax file:
private int activeUsers = 0;
protected void Session_Start(Object sender, EventArgs e)
{
activeUsers++;
Context.Items["activeUsers"] = activeUsers;
}
protected void Application_BeginRequest(Object sender, EventArgs e)
{
Context.Items.Add("activeUsers", activeUsers);
}
protected void Session_End(Object sender, EventArgs e)
{
if(activeUsers > 0)
activeUsers--;
}
protected void Application_End(Object sender, EventArgs e)
{
activeUsers = 0;
}
I would use performance counters instead.
Look under
ASP.NET Application Performance Counters
http://msdn.microsoft.com/en-us/library/fxk122b4.aspx