的OnClick和的OnClientClick [英] OnClick and OnClientClick

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

问题描述

我有一个被另一个页面打开一个弹出页面上的图像按钮

 < ASP:ImageButton的
        ID =Button_kalem_islemikaydet
        =服务器
        的CausesValidation =FALSE
        的ImageUrl =〜/图片/ butonlar /比于克/ Kaydet.jpg
        元:获取ResourceKey =Button_kalem_islemikaydetResource1
        的OnClick =Button_ust_islemikaydet_Click
        的OnClientClick =F2()
        WIDTH =100/>

F2()

 <脚本类型=文/ JavaScript的>
        函数f2(){
            。opener.document.getElementById(TextBox1中)值=Hello World的;
            。opener.document.getElementById(HiddenField1)值=Hello World的;            window.opener.location.href = window.opener.location.href;
        }
< / SCRIPT>

Button_ust_islemikaydet_Click 在aspx.cs文件中实现另一种方法,它更新其显示在父页面中的GridView的数据库表。

我所试图做的是doPostBack我的意思是刷新了开门红(父)page.And这些上面codeS刷新working.However,父页面仍然显示refresh.And前的原因相同的数据是的 的OnClientClick 之前的作品的OnClick
所以我的问题是,有没有什么办法,我可以运行在的OnClick 的方法和完成它,然后运行的OnClientClick 方法是什么?


解决方案

 <表ID =aspnetForm=服务器>
    < ASP:按钮文本=点击我ID =ClickMeButton的OnClick =ClickMeButton_OnClick=服务器/>
    < ASP:HiddenField =服务器ID =UpdateOpenerHiddenFieldVALUE =FALSE/>    <脚本类型=文/ JavaScript的>
        //第一个方法
        变种updateOpenerField = window.document.getElementById(&下;%= UpdateOpenerHiddenField.ClientID%gt;中);
        如果(updateOpenerField.value ===真){
            F2();
            updateOpenerField.value =假;
        }        //为第二做法坐视不管
        函数f2(){
            警报(你好,大开眼界!);
        }
< / SCRIPT>
< /表及GT;
保护无效ClickMeButton_OnClick(对象发件人,EventArgs的发送)
    {
        //第一个方法
        UpdateOpenerHiddenField.Value =真;        //第二个方法
        ClientScript.RegisterStartupScript(this.GetType(),RefreshOpener,F2();,真);
    }

I have an image button on a pop up page which is opened by another page

<asp:ImageButton 
        ID="Button_kalem_islemikaydet" 
        runat="server" 
        CausesValidation="False" 
        ImageUrl="~/images/butonlar/buyuk/Kaydet.jpg"  
        meta:resourcekey="Button_kalem_islemikaydetResource1" 
        OnClick="Button_ust_islemikaydet_Click" 
        OnClientClick="f2()"  
        Width="100" />

f2() is

<script type="text/javascript">
        function f2() {
            opener.document.getElementById("TextBox1").value = "hello world";
            opener.document.getElementById("HiddenField1").value = "hello world";

            window.opener.location.href = window.opener.location.href;            
        } 
</script> 

And Button_ust_islemikaydet_Click is another method implemented in aspx.cs file and it updates the database tables which are shown in the parent page in a GridView.

What I am trying to do is to doPostBack I mean refresh the opener(parent) page.And with these above codes refresh is working.However, parent page still shows the same data before the refresh.And the reason is that OnClientClick works before OnClick method So my question is that is there any way I can run the method on OnClick and finish it and then run the OnClientClick method?

解决方案

<form id="aspnetForm" runat="server">
    <asp:Button Text="Click Me" ID="ClickMeButton" OnClick="ClickMeButton_OnClick" runat="server" />
    <asp:HiddenField runat="server" ID="UpdateOpenerHiddenField" Value="false" />

    <script type="text/javascript">
        //1st approach
        var updateOpenerField = window.document.getElementById("<%= UpdateOpenerHiddenField.ClientID  %>");
        if (updateOpenerField.value === "true") {
            f2();
            updateOpenerField.value = "false";
        }

        // for the 2nd approach just do nothing
        function f2() {
            alert("Hello, opener!");
        }
</script>
</form>


protected void ClickMeButton_OnClick(object sender, EventArgs e)
    {
        //1st approach
        UpdateOpenerHiddenField.Value = "true";

        // 2nd approach
        ClientScript.RegisterStartupScript(this.GetType(), "RefreshOpener", "f2();", true);
    }

这篇关于的OnClick和的OnClientClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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