开发者

How to display an alert box on a non clickable link button

I am having HyperLink on my webfrom in such a way that if proper user login and clicks on the link will navigate him to corresponding page. If not i make that as a non clickable field by using this code

if(isAdmin)
{ // check for admin user
   Link1.NavigateUrl = "Reports.aspx"; 
   Link1.NavigateUr2 = "Delete.aspx";
 } 
else 
{
     Link1.NavigateUrl = "javascript:return void;";
     Link1.NavigateUr2 = "javascript:return void;"; 
}  

In the else part i would like to display an 开发者_开发百科alert box saying that you are not an authorized user.

I also write another code for making that link as non selectable as follows

    LinkButton1.Attributes["OnClick"] = “return false;”; 

So can any one tell how can i write alert message in both the cases


 Link1.NavigateUrl = "javascript:alert('hello'); return false;";

OR

 Link1.Attributes["onclick"] = "alert('hello'); return false";


In your else part add:

string prompt =
 "<script type=\"text/javascript\">alert('You are not an authorized user'); </script>";
   ClientScript.RegisterStartupScript(typeof (Page), "alert", prompt);

Regards

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜