Asif.Ali Asif.Ali - 1 year ago 31
ASP.NET (C#) Question

Only one alert is showing

I have two validation methods (

HasSession()
,
IsUserMatch()
) returns
Boolean
and one method
HasSession()
showing alert box but
IsUserMatch()
method does not showing the alert box

Two Methods are below

private Boolean HasSession()
{
if (Session["USERID"] == null)
{
ShowMessage("Please login first. Thanks...");
return true;
}
else
{
return false;
}
}
private Boolean IsUserMatch(string userid)
{
if ((string)Session["USERID"] == userid)
{
ShowMessage("You can't vote on your own Post/Answer!");
return true;
}
else
{
return false;
}
}


Calling Method is here

protected void lbUpVote_Click(object sender, EventArgs e)
{
if (!HasSession() && !IsUserMatch(lblUserId.Text))
{
// Some code
}
}

Answer Source

If !HasSession() is false IsUserMatch won't be executed.

Some reference for you to read: https://msdn.microsoft.com/en-us/library/2bxt6kc4.aspx

I think the cleanest solution would be:

var sessionResult = HasSession();
var userResult = IsUserMatch();

if(sessionResult && userResult){
    //Do Something
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download