单选按钮列表事件不总是射击 [英] Radiobuttonlist event not always firing

查看:182
本文介绍了单选按钮列表事件不总是射击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个更新搜索功能SelectedIndexChanged事件一个单选按钮列表。一项目的是在ASPX指定,其他附加数据绑定的项目。不管我怎么设置为默认,该项目将不会触发事件。其他所有项目将触发事件。此外,似乎选择了死项目之后,该事件将不会触发的。

我如何追查错误和正确的?这是当前code。

编辑:对不起,如果短版是误导。我不知道该怎么包括。这里是整个页面。

所有的aspx:

 <%@页面语言=C#的MasterPageFile =〜/ MSDS / MSDS.masterEnableEventValidation =假
    AutoEventWireup =真codeFILE =SearchMSDS.aspx.cs继承=MSDS_ByDept标题=NCLWeb - 搜索MSDS%GT;<%@注册大会=SqlWhereBuilder命名空间=UNLV.IAP.WebControls标签preFIX =CC1%GT;
<%@注册大会=AjaxControlToolkit命名空间=AjaxControlToolkit标签preFIX =CC2%GT;
< ASP:内容ID =内容1ContentPlaceHolderID =PageContent=服务器>
    < H2>
        < ASP:标签ID =lblTitle=服务器>搜索活动MSDS< / ASP:标签>< / H>
    <表类=STYLE1>
        &所述; TR>
            < TD风格=WIDTH:435pxVALIGN =顶>
                < ASP:面板=服务器ID =pnlSearchDefaultButton =btnSearch>
                    < ASP:文本框ID =txtSimpleSearch=服务器WIDTH =262px>< / ASP:文本框>
                    < ASP:按钮的ID =btnSearch=服务器文本=搜索WIDTH =96PX的OnClick =btnSearch_Click/>
                    < BR />
                    < ASP:LinkBut​​ton的ID =btnAdvSearch=服务器的OnClick =btnAdvSearch_ClickFONT-SIZE =小>显示高级搜索< / ASP:LinkBut​​ton的>
                < / ASP:面板>
                < ASP:面板ID =pnlAdvSearch=服务器WIDTH =635pxDefaultButton =btnRunAdvSearch>
                    < ASP:按钮的ID =btnRunAdvSearch=服务器的OnClick =btnRunAdvSearch_Click文本=高级搜索/>
                    < CC1:SqlWhereBuilder ID =SqlWhereBuilder1=服务器客户端codeLocation =../的JavaScript / SqlWhereBuilder.js
                        FieldsFile =../ ConfigFiles / SearchMSDS.configOperatorListsFile =../ ConfigFiles / SearchMSDS.config
                        ValueEntryFile =../ ConfigFiles / SearchMSDS.config>
                    < / CC1:SqlWhereBuilder>
                    < BR />
                    < BR />
                < / ASP:面板>
                < CC2:CollapsiblePanelExtender ID =pnlAdvSearch_CollapsiblePanelExtender=服务器
                    CollapseControlID =btnAdvSearch坍塌=真启用=真ExpandControlID =btnAdvSearch
                    的TargetControlID =pnlAdvSearch>
                < / CC2:CollapsiblePanelExtender>
            < / TD>
            < TD VALIGN =顶>
                < ASP:面板ID =pnlStatus=服务器>
                    < ASP:RadioButtonList的ID =rblStatus=服务器AppendDataBoundItems =真
                        的AutoPostBack =真的DataSourceID =SqlDataSource1DataTextField =DisplayValue
                        DataValueField =值OnSelectedIndexChanged =RadioButtonList1_SelectedIndexChanged
                        RepeatDirection =水平CELLPADDING =3CELLSPACING =3
                        的CausesValidation =真可见=真>
                        < ASP:列表项选择=真>所有< / ASP:ListItem的>
                    < / ASP:RadioButtonList的>
                < / ASP:面板>
                < ASP:SqlDataSource的ID =SqlDataSource1=服务器的ConnectionString =<%$的ConnectionStrings:NCLWebConnectionString%>中
                    的SelectCommand =getOptionListSelectCommandType =StoredProcedure的>
                    < SelectParameters>
                        < ASP:参数默认值=msds_StatusNAME =LISTNAME类型=字符串/>
                    < / SelectParameters>
                < / ASP:SqlDataSource的>
                < ASP:的UpdatePanel =服务器ID =UPD2>
                    <&的ContentTemplate GT;
                        < ASP:按钮的ID =btnExport=服务器文本=导出结果
                            的OnClick =btnExport_Click1UseSubmitBehavior =FALSE/>
                    < /&的ContentTemplate GT;
                < / ASP:的UpdatePanel>
            < / TD>
        < / TR>
    < /表>
    < ASP:的UpdatePanel ID =UpdatePanel1=服务器>
        <&的ContentTemplate GT;
            < ASP:的UpdateProgress ID =UpdateProgress1=服务器DisplayAfter =100DynamicLayout =FALSE>
                < ProgressTemplate>
                    < IMG SRC =../图像/ loading.gifALT =载入中...的风格=文本对齐:中心/>
                    < ASP:标签ID =lblProgress=服务器>< / ASP:标签>< / ProgressTemplate>
            < / ASP:&的UpdateProgress GT;
            < ASP:GridView控件ID =gridResults=服务器的DataSourceID =sqlMSDSOnRowDataBound =GridView1_RowDataBound
                AllowPaging =真每页=25AllowSorting =真OnSelectedIndexChanged =gridResults_SelectedIndexChanged
                的AutoGenerateColumns =FALSEEmptyDataText =无匹配的MSDS表。 OnSorted =gridResults_Sorted>
                <柱体和GT;
                    < ASP:BoundField的数据字段=ID的HeaderText =IDInsertVisible =FALSE可见=假
                        只读=真SORTEX pression =ID/>
                    < ASP:BoundField的数据字段=ChemicalTitle的HeaderText =ChemicalTitleSORTEX pression =ChemicalTitle/>
                    < ASP:BoundField的数据字段=制造商的HeaderText =制造商SORTEX pression =制造商/>
                    < ASP:BoundField的数据字段=UsageDept的HeaderText =UsageDeptSORTEX pression =UsageDept/>
                    < ASP:BoundField的数据字段=注意事项的HeaderText =注意事项SORTEX pression =注意事项/>
                    < ASP:BoundField的数据字段=健康的HeaderText =健康可见=假SORTEX pression =健康/>
                    < ASP:BoundField的数据字段=火的HeaderText =火可见=假SORTEX pression =火/>
                    < ASP:BoundField的数据字段=反应性的HeaderText =反应性可见=假SORTEX pression =反应性/>
                    < ASP:BoundField的数据字段=DateUpdated的HeaderText =DateUpdatedSORTEX pression =DateUpdated/>
                < /专栏>
                < SelectedRowStyle背景色=黄色/>
            < / ASP:GridView的>
            < ASP:SqlDataSource的ID =sqlMSDSOnSelected =sqlMSDS_OnSelected=服务器的ConnectionString =<%$的ConnectionStrings:NCLWebConnectionString%>中
                的SelectCommand =SELECT [ID]
                                      [ChemicalTitle]
                                      ,[生产企业]
                                      [UsageDept]
                                      ,[笔记]
                                      ,[健康]
                                      ,[火]
                                      [反应]
                                      [DateUpdated]
                                      FROM [msds_Sheets]OnSelecting =sqlMSDS_Selecting>< / ASP:SqlDataSource的>
        < /&的ContentTemplate GT;
        <&触发器GT;
            < ASP:AsyncPostBackTrigger控件ID =btnSearch事件名称=点击/>
            < ASP:AsyncPostBackTrigger控件ID =btnRunAdvSearch事件名称=点击/>
            < ASP:AsyncPostBackTrigger控件ID =rblStatus事件名称=的SelectedIndexChanged/>
            < ASP:AsyncPostBackTrigger控件ID =btnExport事件名称=点击/>
        < /触发器>
    < / ASP:的UpdatePanel>
    < BR />
< / ASP:内容>

和code-背后:

 列表<串GT; safeWords =新的List<串GT;();保护无效的Page_Load(对象发件人,EventArgs的发送)
{
    pnlStatus.Visible = User.IsInRole(msds_Admin);    gridResults.DataKeyNames =新的String [] {ID};    txtSimpleSearch.Focus();    如果(!的IsPostBack)
    {
        safeWords.Add(删除);
        safeWords.Add(插入);
        safeWords.Add(更新);
        safeWords.Add(设置);
        safeWords.Add(EXEC);
        safeWords.Add(N');        sqlMSDS.SelectCommand + =哪里状态= 0;        会话[SQL] = sqlMSDS.SelectCommand;        尝试
        {
            会话[OriginalSQL] = sqlMSDS.SelectCommand.Remove(sqlMSDS.SelectCommand.IndexOf(去哪儿));
        }
        赶上(例外)
        {
            会话[OriginalSQL] = sqlMSDS.SelectCommand;
        }
    }
}保护无效RadioButtonList1_SelectedIndexChanged(对象发件人,EventArgs的发送)
        {
            ((标签)UpdateProgress1.FindControl(lblProgress))文本=搜索...。            如果(btnSearch.Visible)
            {
                btnSearch_Click(NULL,NULL);                如果(RadioButtonList1.SelectedValue!=全部)
                {
                    sqlMSDS.SelectCommand + =和状态=+ RadioButtonList1.SelectedValue;
                }
                其他
                {
                    //不知怎的,迫使电网不使用状态参数研究
                    。sqlMSDS.SelectCommand =会话[SQL]的ToString();
                }
            }
            其他
            {
                btnRunAdvSearch_Click(NULL,NULL);                如果(RadioButtonList1.SelectedValue!=全部)
                {
                    如果(sqlMSDS.SelectCommand.Contains(去哪儿))
                    {
                        sqlMSDS.SelectCommand + =和状态=+ RadioButtonList1.SelectedValue;
                    }
                    其他
                    {
                        sqlMSDS.SelectCommand + =哪里状态=+ RadioButtonList1.SelectedValue;
                    }
                }
                其他
                {
                    //不知怎的,迫使电网不使用状态参数研究
                    。sqlMSDS.SelectCommand =会话[SQL]的ToString();
                }
            }
        }


解决方案

这是否单选按钮列表指定为AsyncPostBackTrigger另一个UpdatePanel的?如果是这样,请检查下面的链接:<一个href=\"http://forums.asp.net/t/1126914.aspx/1/10?CheckedChanged%20event%20not%20firing%20on%20a%20radio%20button%20within%20UpdatePanel\"相对=nofollow>的CheckedChanged事件的UpdatePanel 内不触发单选按钮

我有重现的行为,并与下面的脚本解决这个问题:

  $(函数(){
        $(输入[类型='无线电']:第一个$(#&LT;%= RadioButtonList1.ClientID%GT;))。ATTR(选中,真正的);
    });

如果您不能使用jQuery的尝试这个JavaScript:

 的window.onload =函数(){
        window.document.getElementById(&下;%= RadioButtonList1.ClientID%GT; _0)检查=真。
    };
保护无效的Page_Load(对象发件人,EventArgs的发送)
    {
        如果(!的IsPostBack)
        {
            ClientScript.RegisterStartupScript(this.GetType(),RadioButtonListDefaultValue的String.Format(window.document.getElementById({0} _0')检查=真;RadioButtonList1.ClientID),TRUE);
        }
    }

I have a radiobuttonlist with a selectedindexchanged event that updates a search function. One of the items is specified in the aspx, and the others are appended databound items. No matter what I set as the default, that item will not fire the event. All other items will fire the event. Also, it seems that after the "dead" item is selected, the event won't fire at all.

How can I track down the error and correct? Here is current code.

EDIT: Sorry if the short version was misleading. I wasn't sure what to include. Here is the whole page.

All aspx:

     <%@ Page Language="C#" MasterPageFile="~/MSDS/MSDS.master" EnableEventValidation="false"
    AutoEventWireup="true" CodeFile="SearchMSDS.aspx.cs" Inherits="MSDS_ByDept" Title="NCLWeb - Search MSDS" %>

<%@ Register Assembly="SqlWhereBuilder" Namespace="UNLV.IAP.WebControls" TagPrefix="cc1" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PageContent" runat="Server">
    <h2>
        <asp:Label ID="lblTitle" runat="server">Search Active MSDS</asp:Label></h2>
    <table class="style1">
        <tr>
            <td style="width: 435px" valign="top">
                <asp:Panel runat="server" ID="pnlSearch" DefaultButton="btnSearch">
                    <asp:TextBox ID="txtSimpleSearch" runat="server" Width="262px"></asp:TextBox>
                    <asp:Button ID="btnSearch" runat="server" Text="Search" Width="96px" OnClick="btnSearch_Click" />
                    <br />
                    <asp:LinkButton ID="btnAdvSearch" runat="server" OnClick="btnAdvSearch_Click" Font-Size="Small">Show Advanced Search</asp:LinkButton>
                </asp:Panel>
                <asp:Panel ID="pnlAdvSearch" runat="server" Width="635px" DefaultButton="btnRunAdvSearch">
                    <asp:Button ID="btnRunAdvSearch" runat="server" OnClick="btnRunAdvSearch_Click" Text="Advanced Search" />
                    <cc1:SqlWhereBuilder ID="SqlWhereBuilder1" runat="server" ClientCodeLocation="../JavaScripts/SqlWhereBuilder.js"
                        FieldsFile="../ConfigFiles/SearchMSDS.config" OperatorListsFile="../ConfigFiles/SearchMSDS.config"
                        ValueEntryFile="../ConfigFiles/SearchMSDS.config">
                    </cc1:SqlWhereBuilder>
                    <br />
                    <br />
                </asp:Panel>
                <cc2:CollapsiblePanelExtender ID="pnlAdvSearch_CollapsiblePanelExtender" runat="server"
                    CollapseControlID="btnAdvSearch" Collapsed="True" Enabled="True" ExpandControlID="btnAdvSearch"
                    TargetControlID="pnlAdvSearch">
                </cc2:CollapsiblePanelExtender>
            </td>
            <td valign="top">
                <asp:Panel ID="pnlStatus" runat="server">
                    <asp:RadioButtonList ID="rblStatus" runat="server" AppendDataBoundItems="True"
                        AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="DisplayValue"
                        DataValueField="Value" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"
                        RepeatDirection="Horizontal" CellPadding="3" CellSpacing="3" 
                        CausesValidation="True" Visible="True">
                        <asp:ListItem Selected="True">All</asp:ListItem>
                    </asp:RadioButtonList>
                </asp:Panel>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NCLWebConnectionString %>"
                    SelectCommand="getOptionList" SelectCommandType="StoredProcedure">
                    <SelectParameters>
                        <asp:Parameter DefaultValue="msds_Status" Name="ListName" Type="String" />
                    </SelectParameters>
                </asp:SqlDataSource>
                <asp:UpdatePanel runat="server" ID="upd2">
                    <ContentTemplate>
                        <asp:Button ID="btnExport" runat="server" Text="Export Results" 
                            OnClick="btnExport_Click1" UseSubmitBehavior="False" />
                    </ContentTemplate>
                </asp:UpdatePanel>
            </td>
        </tr>
    </table>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:UpdateProgress ID="UpdateProgress1" runat="server" DisplayAfter="100" DynamicLayout="False">
                <ProgressTemplate>
                    <img src="../images/loading.gif" alt="Loading..." style="text-align: center" />
                    <asp:Label ID="lblProgress" runat="server"></asp:Label></ProgressTemplate>
            </asp:UpdateProgress>
            <asp:GridView ID="gridResults" runat="server" DataSourceID="sqlMSDS" OnRowDataBound="GridView1_RowDataBound"
                AllowPaging="True" PageSize="25" AllowSorting="True" OnSelectedIndexChanged="gridResults_SelectedIndexChanged"
                AutoGenerateColumns="False" EmptyDataText="No matching MSDS Sheets." OnSorted="gridResults_Sorted">
                <Columns>
                    <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" Visible="false"
                        ReadOnly="True" SortExpression="ID" />
                    <asp:BoundField DataField="ChemicalTitle" HeaderText="ChemicalTitle" SortExpression="ChemicalTitle" />
                    <asp:BoundField DataField="Manufacturer" HeaderText="Manufacturer" SortExpression="Manufacturer" />
                    <asp:BoundField DataField="UsageDept" HeaderText="UsageDept" SortExpression="UsageDept" />
                    <asp:BoundField DataField="Notes" HeaderText="Notes" SortExpression="Notes" />
                    <asp:BoundField DataField="Health" HeaderText="Health" visible="false" SortExpression="Health" />
                    <asp:BoundField DataField="Fire" HeaderText="Fire"  visible="false" SortExpression="Fire" />
                    <asp:BoundField DataField="Reactivity" HeaderText="Reactivity"  visible="false" SortExpression="Reactivity" />
                    <asp:BoundField DataField="DateUpdated" HeaderText="DateUpdated" SortExpression="DateUpdated" />
                </Columns>
                <SelectedRowStyle BackColor="Yellow" />
            </asp:GridView>
            <asp:SqlDataSource ID="sqlMSDS" OnSelected="sqlMSDS_OnSelected" runat="server" ConnectionString="<%$ ConnectionStrings:NCLWebConnectionString %>"
                SelectCommand="SELECT [ID]
                                      ,[ChemicalTitle]
                                      ,[Manufacturer]
                                      ,[UsageDept]
                                      ,[Notes]
                                      ,[Health]
                                      ,[Fire]
                                      ,[Reactivity]
                                      ,[DateUpdated]
                                      FROM [msds_Sheets]" OnSelecting="sqlMSDS_Selecting"></asp:SqlDataSource>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="btnSearch" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="btnRunAdvSearch" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="rblStatus" EventName="SelectedIndexChanged" />
            <asp:AsyncPostBackTrigger ControlID="btnExport" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>
    <br />
</asp:Content>

And code-behind:

    List<String> safeWords = new List<String>();

protected void Page_Load(object sender, EventArgs e)
{
    pnlStatus.Visible = User.IsInRole("msds_Admin");

    gridResults.DataKeyNames = new String[] { "id" };

    txtSimpleSearch.Focus();

    if (!IsPostBack)
    {
        safeWords.Add("delete");
        safeWords.Add("insert");
        safeWords.Add("update");
        safeWords.Add("set");
        safeWords.Add("exec");
        safeWords.Add("N'");

        sqlMSDS.SelectCommand += " Where status = 0 ";

        Session["Sql"] = sqlMSDS.SelectCommand;

        try
        {
            Session["OriginalSQL"] = sqlMSDS.SelectCommand.Remove(sqlMSDS.SelectCommand.IndexOf("Where"));
        }
        catch (Exception)
        {
            Session["OriginalSQL"] = sqlMSDS.SelectCommand;
        }
    }
}

protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ((Label)UpdateProgress1.FindControl("lblProgress")).Text = "Searching...";

            if (btnSearch.Visible)
            {
                btnSearch_Click(null, null);

                if (RadioButtonList1.SelectedValue != "All")
                {
                    sqlMSDS.SelectCommand += " And Status = " + RadioButtonList1.SelectedValue;
                }
                else
                {
                    //Somehow force the grid to research using no status parameter
                    sqlMSDS.SelectCommand = Session["Sql"].ToString();
                }
            }
            else
            {
                btnRunAdvSearch_Click(null, null);

                if (RadioButtonList1.SelectedValue != "All")
                {
                    if (sqlMSDS.SelectCommand.Contains("Where"))
                    {
                        sqlMSDS.SelectCommand += " And Status = " + RadioButtonList1.SelectedValue;
                    }
                    else
                    {
                        sqlMSDS.SelectCommand += " Where Status = " + RadioButtonList1.SelectedValue;
                    }
                }
                else
                {
                    //Somehow force the grid to research using no status parameter
                    sqlMSDS.SelectCommand = Session["Sql"].ToString();
                }
            }
        }

解决方案

Does this RadioButtonList specified as AsyncPostBackTrigger for another UpdatePanel? If so, check following link: CheckedChanged event not firing on a radio button within UpdatePanel

I have reproduce that behaviour and fix this with the following script:

 $(function () {
        $("input[type='radio']:first", $("#<%= RadioButtonList1.ClientID %>")).attr("checked", true);
    });

if you can't use the jQuery try this javascript:

 window.onload = function () {
        window.document.getElementById("<%= RadioButtonList1.ClientID %>_0").checked = true;
    };


protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "RadioButtonListDefaultValue", String.Format("window.document.getElementById('{0}_0').checked = true;", RadioButtonList1.ClientID), true);
        }
    }

这篇关于单选按钮列表事件不总是射击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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