popup alert code for login authentication for page access

Posted by Parthibansk under ASP.NET on 12/25/2014 | Points: 10 | Views : 529 | Status : [Member] | Replies : 11
working on portal application where registered users are only allowed to access certain pages. need a server side popup alert when unregistered users access certain pages.

how to code for the above.

this is my code:

String strUserName = Convert.ToString(Session["username"]); //z
String Name = Convert.ToString(Session["name"]); //

if (strUserName != "")
{
lbluser.Text = "Welcome: " + Session["username"];

}

else
{


if (!string.Equals("ASP.forgot_password_aspx", Page.Page.ToString()))
Response.Redirect("~/index.html");

}




Responses

Posted by: vishalneeraj-24503 on: 12/26/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down
You can use below message in else block as:-It will alert you.

if (strUserName != "")
{
lbluser.Text = "Welcome: " + Session["username"];

}

else
{


if (!string.Equals("ASP.forgot_password_aspx", Page.Page.ToString()))
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "javascript alert", "alert('your message goes on');", true);

Response.Redirect("~/index.html");
}

}

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Parthibansk on: 12/26/2014 [Member] Starter | Points: 25

Up
0
Down
alert popup not working

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/26/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi,
Have you taken scriptmanager control on page because this alert will work on that only.
Kindly take scriptmanager on page.

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/26/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi,
If you do not have ScriptManager control on page,then write below code:-

Page.ClientScript.RegisterStartupScript(this.GetType(), "Javascript alert", "alert('hello');",true);

It will definitely work.

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Parthibansk on: 12/26/2014 [Member] Starter | Points: 25

Up
0
Down
tried above but still alert not working

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/26/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi,send me your code,so that i can check.

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Parthibansk on: 12/26/2014 [Member] Starter | Points: 25

Up
0
Down
<td><a href="index.html" class="linktab">Home</a></td>
<td><a href="objectives.html" class="linktab">Objectives</a></td>
<td><a href="achievers.html" class="linktab">Achievers</a></td>
<td><a href="#" class="linktab1" >Careers/Jobs</a></td>
<%--<td><a href="javascript:void(0)" class="linktab1" >Careers/Jobs</a></td>--%>
<td><a href="gallery.html" class="linktab">Gallery</a></td>
<td><a href="partner.html" class="linktab">Association/Partners</a></td>
<td><a href="contact.html" class="linktab">Contact Us</a> </td>
</tr>

protected void Page_Load(object sender, EventArgs e)
{
String strUserName = Convert.ToString(Session["username"]); //z
String Name = Convert.ToString(Session["name"]); //

if (strUserName != "")
{
lbluser.Text = "Welcome: " + Session["username"];

}

else
{

// string message = "alert('Login to access page')";
//ScriptManager.RegisterClientScriptBlock((sender as Control), this.GetType(), "alert", message, true);
if (!string.Equals("ASP.forgot_password_aspx", Page.Page.ToString()))
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Javascript alert", "alert('hello');", true);

// Page.ClientScript.RegisterStartupScript(this, this.GetType(), "javascript alert", "alert('Login to access page');", true);

Response.Redirect("~/index.html");

}

}

}

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/26/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi,

There must be something happening at your browser end or application end.
May be your browser is preventing popup.Because i have checked this at my end,alert message is showing here.

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: kgovindarao523-21772 on: 12/26/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,

I think Vishal approach is correct, but the issue is with Response.Redirect.
Try to comment "Response.Redirect("~/index.html");" and check whether alert is coming or not.

if its coming, check with some changes in the code
if (!string.Equals("ASP.forgot_password_aspx", Page.Page.ToString())) 
{
Response.Redirect("~/index.html");
ScriptManager.RegisterStartupScript(this, this.GetType(), "javascript alert", "alert('your message goes on');", true);
}


Revert back with your update.

Thank you,
Govind

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Parthibansk on: 12/26/2014 [Member] Starter | Points: 25

Up
0
Down
govind,

i comment Response.Redirect("~/index.html");" popup alert coming, but page is redirecting to career.aspx page without signingin.

i even tried above code, no alert coming.. page is redirecting to index.html

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/26/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi,
After Response.Redirect ,no code will be executed.
It is just like return function.
So place your code before Response.Redirect method.

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response