必须点击一个按钮两次,以触发一个事件 [英] Must click a button twice to fire an event

查看:246
本文介绍了必须点击一个按钮两次,以触发一个事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个是动态创建以显示从数据库检索信息的数据网格。数据网格由多个绑定列和每一行,视图和删除按钮两粒扣列。

I have a data grid that is created dynamically to display information retrieved from a database. The data grid consists of multiple bound columns and two button columns for each row, a view and a delete button.

单击任一按钮调用的Page_Load()方法Page.IsPostBack为假。

Clicking either button calls the Page_Load() method with Page.IsPostBack as false.

    if (!Page.IsPostBack)
    {           
        this.bindForm(); // Populates drop down lists that the user can select     
        setAccess(false); // Sets access for the page 

        // Stuff commented out to avoid confusion                   
    }
    else
    {
        bindDynamicGrids(); // Create the data grid(s) and populate them           
    }   

所以,当我第一次按一下按钮上面的code被调用的IsPostBack假的,动态网格坐上开往。但是,按钮单击事件不火。当我点击该按钮第二次,Page_Load中被调用的IsPostBack假的,执行bindDynamicGrids后()按钮单击事件。我无法理解在第一和第二次点击之间的差。

So when I first click the button the above code gets called with IsPostBack false, and the dynamic grids get bound. But, the button click event does not fire. When I click the button a second time, Page_Load is called with IsPostBack false, and after executing bindDynamicGrids() the button click event is fired. I cannot understand the difference between the first and second click.

我看过几个线程;

<一个href=\"http://stackoverflow.com/questions/297217/asp-net-c-need-to-$p$pss-a-button-twice-to-make-something-happen\">ASP.NET C#中,需要preSS一个按钮两次,使事情发生

的http:// forums.asp.net/t/1783694.aspx?ASP+NET+Button+needs+to+be+clicked+twice

要试图理解这个问题,但我一定是失去了一些东西。从我所从第二链路汇聚,会话变量可能会得到在click事件,这也被在Page_Load中设置设置,这是命令所有的问题。如果是这样的情况下,我没有看到它正在发生。

To attempt to understand the issue, but I must be missing something. From what I am gathering from the second link, a session variable may be getting set in the click event, which is also being set in Page_Load, and this is all an issue with ordering. If that is the case I am not seeing where it is happening.

当它不回发bindForm()方法被调用,其中填充所有下拉列表。编辑click事件填充与该行的值的下拉菜单,但click事件始终是一个回和形式已被绑定。

When it is not a post back the bindForm() method is called, which populates all drop down lists. The edit click event populates those drop downs with the values from the row, but the click event is always a post back and the form has already been bound.

我也认为有一个脚本自动双击按钮,随时随地用户单一的点击,但我一直没能找到列按钮,一个onclick事件属性。可以提供任何帮助将是惊人的。

I have also considered having a script automatically double click one of the buttons anytime the user single clicks, but I have not been able to find an "OnClick" property for the column button. Any help that could be provided would be phenomenal.

推荐答案

的事情是,该按钮单击事件Page_Load事件意味着过滤没有得到第一回传应用后会发生。它已被更新第二回传,你看到的过滤。
您可以尝试你的Page_Load事件的code移动到preRender所以重装按钮点击事件发生后,

The thing is, that the button click event happens after the Page_Load event meaning that the filtering does not get applied on the first postback. It has been updated on the second postback and you see the filtering. You can try to move the code of your page_load event to OnPreRender so the reload happens after the button click event.

有关更多信息,请看这里:的按钮需要点击两次
 和<一个href=\"http://stackoverflow.com/questions/297217/asp-net-c-need-to-$p$pss-a-button-twice-to-make-something-happen\">here

for more information look here: Button needs to be clicked twice and here

这篇关于必须点击一个按钮两次,以触发一个事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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