简体   繁体   English

当输入控件放置在asp GridView中时,页面加载不触发

[英]Page Load not firing when input control placed in an asp GridView

I have a gridview which displays product information on the index page of my site for a user. 我有一个gridview,它在我的网站的索引页面上为用户显示产品信息。 I want to extend this to allow the user to tick a checkbox if they have reviewed a product. 我想扩展此范围,以允许用户在检查产品时勾选复选框。

However, after adding the check box column into my gridview template, when i try to search multiple times the Page_Load event of my index page stops firing, this causes an issue as some of the events further down the execution tree require the object that is initialised at page load. 但是,在将复选框列添加到我的gridview模板中之后,当我尝试多次搜索索引页的Page_Load事件停止触发时,这会导致问题,因为执行树下的某些事件需要初始化的对象在页面加载时。

The problem seems to be that placing any asp input control inside the gridview is somehow preventing Page_Load from firing before the DataSources OnSelecting and OnSelected and the Grids OnRowDataBound events but i can't see why. 问题似乎是,将任何asp输入控件放置在gridview内都以某种方式阻止了Page_Load在DataSources OnSelecting和OnSelected以及Grids OnRowDataBound事件之前触发,但我不知道为什么。

Here is my sample code, I can't see what I'm doing wrong here. 这是我的示例代码,在这里看不到我做错了什么。

Index.aspx.cs Index.aspx.cs

private ProductSearch productSearch

protected void Page_Load(object sender, EventArgs e)
{
    productSearch = new ProductSearch(GetSearchParameters());
    productSearch.PageLoad()
}

protected void ProductsSelecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
    e.InputParameters["searchParams"] = productSearch.GetSearchParams();
}

protected void ProductsSelected(object sender, ObjectDataSourceStatusEventArgs e)
{
    productSearch.SetExportToCsvButton();
}

protected void ProductsPageIndexChanging(object sender, GridViewPageEventArgs e)
{
    dgProducts.PageIndex = e.NewPageIndex;
}

protected void ProductsOnRowDataBound(object sender, GridViewRowEventArgs e)
{
    productSearch.ProductsRowDataBound(e.Row);
}

Index.aspx Index.aspx

<%@ Page Language="C#" MasterPageFile="~/Admin/AdminMaster.master" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="Web.Admin.Index" %>
<asp:Content ContentPlaceHolderID="DataFrame" runat="server">
    <asp:GridView ID="dgProducts" runat="server" AllowPaging="True" AllowSorting="True" EnableViewState="False"
            AutoGenerateColumns="False" DataSourceID="dsProducts" PagerSettings-Position="TopAndBottom" DataKeyNames="ProductNo, KitID"
            OnPageIndexChanging="ProductsPageIndexChanging" OnRowDataBound="ProductsOnRowDataBound"
            EmptyDataText="There are no products matching your search." meta:resourcekey="dgProducts" onrowcreated="ProductsRowCreated">
        <HeaderStyle Font-Size="Small" />
        <Columns>
            <asp:TemplateField HeaderText="Reviewed">
                <ItemTemplate>                        
                    <asp:CheckBox runat="server" ID="chkReviewed" class="reviewedCheckbox" Checked="False" />                        
                </ItemTemplate>
            </asp:TemplateField>
        </Columns
    </asp:GridView>
    <asp:ObjectDataSource ID="dsProducts" runat="server" EnablePaging="True" SelectMethod="ProductAndKitSearchByParams"
            TypeName="ProductSearchController.ProductSearch" onselecting="ProductsSelecting" SortParameterName="SortParameter"
            SelectCountMethod="SelectVirtualCount" OnSelected="ProductsSelected">
        <SelectParameters>
            <asp:Parameter ConvertEmptyStringToNull="true" DefaultValue="" Name="searchParams" Type="Object" />
        </SelectParameters>
    </asp:ObjectDataSource>
</asp:Content>

Check you master page contentplaceholderid and provide it in content page like this: 检查您的母版页contentplaceholderid并在内容页中提供它,如下所示:

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"></asp:Content>

and also check your content page codebehind file name should be same as mention in page directives. 并检查您的内容页面代码背后的文件名应与页面指令中提及的相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET事件不在包含大型GridView控件的页面中触发 - ASP.NET Events not firing in page containing large GridView control 类型为“ GridView”的控件“ ctl00_ContentPlaceHolder1_ gridview”必须置于“ ASP主页面”中 - Control 'ctl00_ContentPlaceHolder1_ gridview ' of type 'GridView' must be placed inside the form IN ASP MASTER PAGE 在asp.net Gridview控件中触发的事件序列是什么? - What is the sequence of events firing off in asp.net Gridview control? 使用Timer(asp.net)放置在UpdatePanel中时,GridView闪烁 - GridView flickering when placed inside UpdatePanel with Timer (asp.net) ASP.NET Page_Load没有触发 - ASP.NET Page_Load is not firing 当链接到另一个页面 asp.net 时触发 Page_Load - Page_Load firing when following link to another page asp.net 删除页面加载控件时的ASP.NET问题 - ASP.NET issue when removing Control on Page Load 当用户控件完成在ASP.NET中的加载时,将事件触发到父页面 - Firing an event to the parent page when a user control finishes loading in ASP.NET 动态放置的用户控件asp.net C#无法触发事件 - Event not firing with dynamically placed user control asp.net c# 弹出窗口中放置的Web用户控件的按钮单击事件未触发-Asp.net Webforms - Button Click Event of Web User Control that is placed inside a popup not firing - Asp.net Webforms
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM