alex_lo

导航

服务端控件调用JS

1.关闭窗口,并提交表单。

 

<asp:Button ID="Button1" OnClientClick="window.open('', '_parent', '');
            window.close();" runat="server" Text="关闭当前窗口" />

 

 

2.修改CSS属性

方法一:

 

 

//page:

<asp:Button ID="Button2" runat="server" Text="写入值,并隐藏空间" OnClick="Button2_Click" />

 

 

 

//code_behind:

protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Write("<script >
function   window.onload(){
document.getElementById('Label2').style.display = 'none';}</script>");
        }

 

 

方法二:

 

//page:

<asp:Button ID="Button3" runat="server" Text="写入值,并隐藏空间2"  onclick="Button3_Click"  />

 

 

 

//code_behind

protected void Button3_Click(object sender, EventArgs e){
            Label1.Text = "done2";
            ClientScript.RegisterStartupScript(Page.GetType(), "", "change();", true);
        }

 

 

误区:

  不能使用onClientClick() 来实现;服务端button执行顺序: 先onClientClick执行js代码修改CSS样式,再发送请求。服务端重新加载模板,构造新的html页面发送给客户端。所以只能先执行后台代码,再调用js才能有效修改css样式.

3.利用js灵活提交部分表单

  

<input type="button" value="AAA" onclick="sub()" />

<script type="text/javascript">

        function sub() {

     var value = document.getElementById('btn').value;//有value属性

     var value = document.getElementById("Label3").innerText//label等无value属性
            var att = document.getElementById('Label2').getAttributeNode('id').value;

    

            window.location.href = 'WindowsClose.aspx?value='+value+'&att='+att

        }
    </script>

 

 

 

posted on 2012-09-24 17:18  alex_lo  阅读(209)  评论(0编辑  收藏  举报