validation conflicts with routing - asp.net

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?

Related

Create specific LoginError asp.net

I'm using the LoginPage by .net 4.5.
When the fields are empty I get an error in red which say I can't connect.
What I want to do, is when I enter username and passwords, I try to log into DB, and if I get false, I want a custom error which says I can't log into DB.
Here is the code:
protected void LoginButton_Click(object sender, EventArgs e)
{
if (!DBHandle.DBConnect(UserLogin.UserName, UserLogin.Password))
{
}
}
protected void UserName_TextChanged(object sender, EventArgs e)
{
}
protected void UserLogin_LoginError(object sender, EventArgs e)
{
UserLogin.FailureText = "asdad";
}
What I have to put in the condition, that cause to get to LoginError?
Thanks!

Registered HttpApplication events in ASP.NET

I have the following query:
In ASP.NET Global.ascx file following HttpApplication events are defined:
protected void Application_Start(object sender, EventArgs e)
{
}
protected void Session_Start(object sender, EventArgs e)
{
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
}
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
}
protected void Application_Error(object sender, EventArgs e)
{
}
protected void Session_End(object sender, EventArgs e)
{
}
protected void Application_End(object sender, EventArgs e)
{
}
As I can understand, these are HttpApplication event handlers. But there are lots of other events also. Are the Global.ascx events are only registered events? If not then, What are the other events those had been registered?
Also, say I have implemented a HttpModule on implementing Application_BeginRequest eventhandler. Now, the ASP.NET Framework also implemented the same. Then would my implementation overrides the Framework ones?
You can attach as many as handlers to an event. For more information read MSDN pages on - Handling events.
Read MSDN - Life Cycle Events and the Global.asax file and ASP.NET Application Life Cycle Overview for IIS 7.0

Routing halts validations' client-side processes. How can I solve this?

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?

How does Global.asax PostAuthenticateRequest event binding happen?

How can I use the PostAuthenticateRequest event of Global.asax? I'm following this tutorial and it mentions that I have to use the PostAuthenticateRequest event. When I added the Global.asax event it created two files, the markup and the code-behind file. Here is the content of the code-behind file
using System;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
namespace authentication
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
}
protected void Session_Start(object sender, EventArgs e)
{
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
}
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
}
protected void Application_Error(object sender, EventArgs e)
{
}
protected void Session_End(object sender, EventArgs e)
{
}
protected void Application_End(object sender, EventArgs e)
{
}
}
}
Now when I type the
protected void Application_OnPostAuthenticateRequest(object sender, EventArgs e)
It is successfully called. Now I want to know how is the PostAuthenticateRequest bound to this Application_OnPostAuthenticateRequest method? How can I change the method to some other?
Magic..., a mechanism called Auto Event Wireup, the same reason you can write
Page_Load(object sender, EventArgs e)
{
}
in your code-behind and the method will automatically be called when the page loads.
MSDN description for System.Web.Configuration.PagesSection.AutoEventWireup property:
Gets or sets a value indicating whether events for ASP.NET pages are automatically connected to event-handling functions.
When AutoEventWireup is true, handlers are automatically bound to events at run time based on their name and signature. For each event, ASP.NET searches for a method that is named according to the pattern Page_eventname(), such as Page_Load() or Page_Init(). ASP.NET first looks for an overload that has the typical event-handler signature (that is, it specifies Object and EventArgs parameters). If an event handler with this signature is not found, ASP.NET looks for an overload that has no parameters. More details in this answer.
If you wanted to do it explicitly you would write the following instead
public override void Init()
{
this.PostAuthenticateRequest +=
new EventHandler(MyOnPostAuthenticateRequestHandler);
base.Init();
}
private void MyOnPostAuthenticateRequestHandler(object sender, EventArgs e)
{
}

asp.net ObjectDataSource error handling

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)
{
}
}

Resources