一个点击不要冷杉 [英] a href click dont firingen

查看:105
本文介绍了一个点击不要冷杉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 Control myControl1 = FindControl(  btn1); 
if (myControl1!= null
{
myControl1。 Visible = true ;


}

控制myControl2 = FindControl( BTN2\" );
if (myControl2!= null
{
myControl2。 Visible = true ;
}



在我的页面加载中我有两个我显示两个控件。

onclick在aspx页面我有这个< br $>


  window  .onload =  function (e){
document .getElementById( btn1)。style.visibility = hidden ;
document .getElementById( btn2).style.visibility = hidden;
};



我这里有这个代码,因为我不会只在服务器端在客户端显示它们

但隐藏他们在hrefs上的服务器端点击事件不是firingen?







  function  ShowItems(){


document 。 getElementById( btn1)。style.visibility = display;
document .getElementById( btn2).style.visibility= none;

}


function DontDisplayItems()
{

document .getElementById( btn1)style.visibility = none;
document .getElementById( btn2).style.visibility= display;

}







 <   div     id   =  btn1    style   =  float:right;       runat   = 服务器 >  
< span class =code-keyword>< a href = > 按钮1 < / a >


< / div >
< div id = btn2 样式 = float:right; runat = server >
< a href = > 按钮2 < / a >


< / div >





问题是我的按钮不会显示:

解决方案

当你通过设置.Visible = false隐藏C#中的内容然后控件不在发送到客户端的html中。因此,您无法在JavaScript中更改其可见性。



为此,请勿使用.Visible属性,而只使用JavaScript中的显示或可见性属性。

Control myControl1 = FindControl("btn1");
                if (myControl1 != null)
                {
                    myControl1.Visible = true;


                }

                Control myControl2 = FindControl("btn2");
                if (myControl2 != null)
                {
                    myControl2.Visible = true;
                }


In my page load i have this two that i display two controls.
onclick in aspx page i have this

window.onload = function (e) {
        document.getElementById("btn1").style.visibility = "hidden";
        document.getElementById("btn2").style.visibility = "hidden";
    };


I have this code here because i dont wont to display them on client side only on server side
but hiding them in server side click event on a hrefs is not firingen?



function ShowItems() {


            document.getElementById("btn1").style.visibility="display";
            document.getElementById("btn2").style.visibility="none";

        }


    function DontDisplayItems()
    {

        document.getElementById("btn1")style.visibility="none";
        document.getElementById("btn2").style.visibility="display";

    }




<div id="btn1" style="float:right;"  runat="server">
         <a href="#"  >Button 1</a>


    </div>
    <div id="btn2" style="float:right;"  runat="server">
         <a href="#"   >Button 2</a>


    </div>



The problem is that my button wont be display:

解决方案

When you hide something in C# by setting .Visible = false then the control is not in the html at all that is sent to the client. Therefore you cannot change it's visibility in JavaScript.

To do so, don't use the .Visible property but instead use display or visibility properties in JavaScript only.


这篇关于一个点击不要冷杉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆