Web用户控件不在asp.net中调用if(!ispostback)事件 [英] web user control not invoking if(!ispostback) event in asp.net

查看:62
本文介绍了Web用户控件不在asp.net中调用if(!ispostback)事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在c#中有asp.net网站。



i已添加我添加了一个下拉列表的web用户控件。

我在page_load中的if(!ispostback)中绑定了这个ddl。



但不幸的是,它没有调用!ispostback。



任何人都可以帮助我,为什么会这样。



代码:

Hi guys,

I have asp.net web site in c#.

i have add web user control in which i have added a dropdownlist.
i'm binding this ddl in the if(!ispostback) in page_load.

But unfortunately, its not invoking the !ispostback.

Can anyone plzzz, help me, why it so.

code:

public partial class TicketUserControl : System.Web.UI.UserControl
{
    //DataAccessLayer.DAL dl = new DataAccessLayer.DAL();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)// not binding the ddl, its not getting in the loop.
        {
            DataTable dt = new DataTable();

            dt = (DataTable)Session["Get_AllPriceRef"];

            DropDownList ddl = ddlNewRef;
            ddl.DataSource = dt;
            ddl.DataTextField = "New_Ref";
            ddl.DataValueField = "RecID";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem("--Select--", "0"));
        }
    }
}

推荐答案

您可能需要阅读文档。

You might want to read up on the documentation.
[BrowsableAttribute(false)]
public bool IsPostBack { get; }

Property Value
Type: System.Boolean
true if the page is being loaded in response to a client postback; otherwise, false.

以下示例显示如何测试的值加载页面时, IsPostBack 属性,以确定页面是第一次呈现还是响应回发。如果页面是第一次呈现,则代码调用 页面验证 方法。

The following example shows how to test the value of the IsPostBack property when the page is loaded in order to determine whether the page is being rendered for the first time or is responding to a postback. If the page is being rendered for the first time, the code calls the Page.Validate method.

页面标记(未显示)包含 RequiredFieldValidator 控制显示如果没有输入所需的输入字段,则为星号。致电 Page 验证 会导致在呈现页面时立即显示星号,而不是等到用户单击提交按钮。回发后,您不必调用 页面验证 ,因为该方法是作为 页面 生命周期。

The page markup (not shown) contains RequiredFieldValidator controls that display asterisks if no entry is made for a required input field. Calling Page.Validate causes the asterisks to be displayed immediately when the page is rendered, instead of waiting until the user clicks the Submit button. After a postback, you do not have to call Page.Validate, because that method is called as part of the Page life cycle.


谢谢大家,



实际上它的更新面板正在解决问题。



当我删除更新时面板,然后代码工作正常。
Thanks everyone,

Actually its update panel which is making the problem.

When I removed update panel, then the code is working fine.


这篇关于Web用户控件不在asp.net中调用if(!ispostback)事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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