I have a page that do some validations in Page_Load method
According this validation i need to block the access to this page.
Example:
protected void Page_Load(object sender, EventArgs e){
if (!IsPostBack)
{
if (MyValidation)
{
// The page is loaded an de user get access
}
else
{
// Here, i need to block the access to this page
// Redirect, close browser, etc ...
}
} }
actually, a have this code...
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// The page is loaded an de user get access
Services.ChatService ws = new ChatService();
KeyValuePair<int, string> kvp = ws.AtenderClienteChat();
if (kvp.Key > 0)
{
this.CodigoChamadoChat = CriaChamado(kvp.Key, kvp.Value);
odsChamado.SelectParameters["cd_chamado"].DefaultValue = this.CodigoChamadoChat.ToString();
fvChamadoChat.DataBind();
// recupero da aplication a lista que contém os chat em andamento
Application.Lock();
List<chat_andamento> lstChatAndamento = (List<chat_andamento>)Application["ListChatAndamento"];
// Instancio e inicializo uma nova chat_andamento
chat_andamento ca = new chat_andamento(this.CodigoChamadoChat, kvp.Key, kvp.Value, WebUtil.GetUserId());
lstChatAndamento.Add(ca);
// Devolvo para a Application a lista preenchida
Application["ListChatAndamento"] = lstChatAndamento;
Application.UnLock();
// Altero o titulo da pagina para facilitar localização do tecnico quando estiver com mais de um chat em andamento
chamado c = (chamado)fvChamadoChat.DataItem;
Page.Title = kvp.Value + " (" + c.cliente.nomecomercial_cliente + ")";
// Envia uma mensagem de boas vindas
Services.ChatService sw = new ChatService();
sw.SendMessage(this.CodigoChamadoChat, "Olá " + kvp.Value + ", em que posso ajudar?", 2);
//RetrieveMessages();
ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "RetMessTec", "timer_onTick();", true);
}
else
{
// Here, i need to block the access to this page
// Redirect, close browser, etc ...
// aqui é preciso abortar o carregamento da pagina
// talvez mostrar um DIV sobre toda a pagina inpedindo interação do usuário
ScriptManager.RegisterClientScriptBlock(this.Page, typeof(Page), "CliAtendido", "self.close();", true);
//this.divGeral.Visible = false;
//this.divErro.Visible = true;
}
}
}
and this code give me this error
Server Error in '/' Application.
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.
Source Error:
Line 173: function EncerrarChamado() { Line 174:
// Primeiramente mostra o combo para seleção do motivo Line 175: var divMotivo = $('#<%= fvChamadoChat.FindControl("divMotivo").ClientID %>'); Line 176: if (divMotivo.hasClass('Hidden')) { Line 177:
divMotivo.removeClass('Hidden');Source File: c:\Projetos\Avalon\Avalon\View\Forms\frmChatTecnico.aspx Line: 175
Line 175 have some JQuery statements that retrieve a div inside a FormView
THE QUESTION 1 IS: Hoe to block access (Redirect, close browser, etc...) if the validation goes to "Else" part of my validation
THE QUESTION 2 IS: If my validation goes to "Else" the FormView is not created and if it is not created the javascript cant access it.
Any ideas ?