Desativando o botão direito do mouse em navegadores, javascript com chamada pelo C# ou VB
OBS.: testado no IE6 e Firefox 1.5

C#

chamada:
CODE
protected void Page_Load(object sender, EventArgs e)
    {
            if (!IsPostBack)
            {
                this.RetirarPropriedades();
            }
    }


função:
CODE
private void RetirarPropriedades()
    {
        string cstext = @"
                                var message='';
                                function clickIE() {
                                    if (document.all){
                                        return false;
                                    }
                                }
                                function clickNS(e) {
                                    if(document.layers||(document.getElementById&&!document.all)){
                                        if(e.which==2||e.which==3) {
                                            return false;
                                        }
                                    }
                                }
                                if (document.layers){
                                    document.captureEvents(Event.MOUSEDOWN);
                                    document.onmousedown=clickNS;
                                }else{
                                    document.onmouseup=clickNS;
                                    document.oncontextmenu=clickIE;
                                }
                                document.oncontextmenu = new Function('return false');    
                             ";

        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "RetirarPropriedades", cstext, true);
    }




VB

chamada:
CODE
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (Not IsPostBack) Then
            Me.RetirarPropriedades()
        End If
    End Sub


função:
CODE
Private Sub RetirarPropriedades()
        Dim cstext As String = ""

        cstext &= "var message='';"
        cstext &= "     function clickIE() {"
        cstext &= "          if (document.all){"
        cstext &= "              return false;"
        cstext &= "          }"
        cstext &= "     }"
        cstext &= "     function clickNS(e) {"
        cstext &= "         if(document.layers||(document.getElementById&&!document.all)){"
        cstext &= "             if(e.which==2||e.which==3) {"
        cstext &= "                 return false;"
        cstext &= "             }"
        cstext &= "         }"
        cstext &= "     }"
        cstext &= "     if (document.layers){"
        cstext &= "         document.captureEvents(Event.MOUSEDOWN);"
        cstext &= "         document.onmousedown=clickNS;"
        cstext &= "     }else{"
        cstext &= "         document.onmouseup=clickNS;"
        cstext &= "         document.oncontextmenu=clickIE;"
        cstext &= "     }"
        cstext &= "     document.oncontextmenu = new Function('return false');    "

        Me.Page.ClientScript.RegisterStartupScript(Me.GetType, "RetirarPropriedades", cstext, True)
    End Sub



t+

Você gostou? Comente no fórum!

Mais recentes em .Net

Exibindo mapa usando a api do google.
Por Ivan - Usando subgurim.net...
Compactando arquivos com c#
Por Joaquim Tito - Dotnet zip library...
Dez razões para adotar o asp.net 3.5
Por DPLF - 10 razões para adotar o asp.net 3.5publicado em: 20/03/2008...
Download de arquivos com asp.net
Por Leonard - Iremos aprender como fazer download de arquivos com o asp.net...
Emitindo beep com c#
Por Leonard - Iremos aprender como emitir um beep apartir de uma dll no c#...

Ver mais Artigos de .Net.

Ver e retirar outras dúvidas no fórum Webly.

Alguns Direitos Reservados | RSS | O Fórum

Webly Portal e Fóruns - Internet + Humana | Design by ArthurHenrique.com