Request.Params(__EVENTTARGET) Showing NULL Reference Exception in Page_Load
I am having a page where I have checked the POST event of submit button in page_load as below
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Request.Params("__EVENTTARGET").ToString().ToUpper().Contains("BTNLOGIN") Then
If Request.RequestType.ToString().ToUpper() <> "POST" Then
Response.Redirect("ErrorPage.html", True)
Return
End If
End If
If Request.UrlReferrer = Nothing Then
Response.Redirect("index.aspx", True)
End If
If Not Page.IsPostBack Then
End If
End Sub
This would be giving me error as:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
On below line:
If Request.Params("__EVENTTARGET").ToString().ToUpper().Contains("BTNLOGIN") Then