我的Page_Load在对该页面的任何调用中都会打两次。
我正在使用trirand dll来jqgrid。刷新页面时,它会调用page_load两次。没有src空白的图像标记或写入注释处理程序。
请帮忙 ASPX页面
<%@ Page Title="" Language="C#" MasterPageFile="~/app_assets/main.master" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="RM_Admin.rm_app_infrastructure.business_rules._default" %>
<%@ Register Assembly="Trirand.Web" TagPrefix="trirand" Namespace="Trirand.Web.UI.WebControls" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cph_main_head_1" runat="server">
<link href="../../app_assets/js/jquery/plugins/colorbox/colorbox.css" rel="stylesheet" type="text/css" />
<script src="../../app_assets/js/jquery/plugins/colorbox/jquery.colorbox.js" type="text/javascript"></script>
<link href="../rm_app.css" rel="stylesheet" type="text/css" />
<script src="../rm_app.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cph_main_body_1" runat="server">
<form id="Form1" runat="server">
<div id="page_content" class="page_content">
<input id="btnCreateRule" type="button" value="Create Business Rule" />
<asp:DropDownList ID="ddlst_tags" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlst_tags_SelectedIndexChanged"></asp:DropDownList>
<br />
<br />
<trirand:JQGrid runat="server" ID="grdRelease" Width="900px" Height="360" OnSearching="grdRelease_Searching">
<Columns>
<trirand:JQGridColumn
Searchable="false"
TextAlign="Center"
Width="40"
Sortable="false"
CssClass="EditImage" />
<trirand:JQGridColumn
HeaderText="Business Rule"
DataField="business_rule_id"
DataType="Int"
Searchable="true"
SearchToolBarOperation="Contains"
TextAlign="Center"
Width="150" />
<trirand:JQGridColumn
HeaderText="Rule Name"
DataField="rule_name"
DataType="String"
Searchable="true"
SearchToolBarOperation="Contains"
CssClass="divDescription"
Width="300" />
<trirand:JQGridColumn
HeaderText="Rule description"
DataField="rule_description"
TextAlign="Left"
DataType="String"
Searchable="true"
SearchToolBarOperation="Contains"
CssClass="divDescription"
Width="400" />
<trirand:JQGridColumn
HeaderText="Created Date"
DataField="create_date"
Searchable="true"
SearchToolBarOperation="Contains"
DataType="DateTime"
TextAlign="Center" />
</Columns>
<ToolBarSettings ShowSearchToolBar="true" />
<PagerSettings PageSize="50" PageSizeOptions="[50]" />
</trirand:JQGrid>
<div id="divShowContent" class="ActionPopupContent" style="display: none;"></div>
</div>
</form>
服务器端代码。
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
bind_tag_dropdown();
BindBusinessRuleGrid(0);
}
}
public void BindBusinessRuleGrid(int n_tag_id)
{
obj_dt = obj_document.GetBusinessRules(n_tag_id);
foreach (DataRow dr in obj_dt.Rows) // search whole table
{
dr["rule_description"] = Regex.Replace(dr["rule_description"].ToString(), "<.*?>", string.Empty).Replace("\r\n", string.Empty); //remove all the html tag and new line command
dr["rule_name"] = Regex.Replace(dr["rule_name"].ToString(), "<.*?>", string.Empty).Replace("\r\n", string.Empty);//remove all the html tag and new line command
}
grdRelease.DataSource = obj_dt;
grdRelease.DataBind();
}
protected void bind_tag_dropdown()
{
ddlst_tags.DataSource = Tools.retrieve_tags();
ddlst_tags.DataTextField = "tag_title";
ddlst_tags.DataValueField = "tag_id";
ddlst_tags.DataBind();
}
答案 0 :(得分:0)
网格本身自动返回到 它托管的页面以加载数据。本质上,页面首先 加载(Page_Load执行一次),然后一旦页面加载, grid执行GET请求回服务器以获取其数据(因此 PostBack = False的第二个请求。