Click here to Skip to main content
15,886,079 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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"));
        }
    }
}
Posted
Comments
ZurdoDev 17-Oct-14 12:26pm    
What do you mean it is not invoking it? Put a breakpoint on your if statement, make sure this control is on a page, and then run the page.
abdul subhan mohammed 17-Oct-14 17:13pm    
Dude, I have run debug then only i came to know that it is not getting into the loop[if(!ispostback)].
I want to know why n how could i solve this, plz.
ZurdoDev 18-Oct-14 10:44am    
Put the breakpoint on the if, not inside the if. And if there is more code you haven't shown us put the breakpoint at the top of the page_load, first line. If it still isn't hitting the breakpoint then either you've got an issue with Visual Studio or you aren't actually using that control (it would seem.)
[no name] 17-Oct-14 20:11pm    
Is the page being rendered for the first time or is responding to a postback? I ask because there are other methods you can use depending on the action called.

You might want to read up on the documentation.
C#
[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.

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.

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.

 
Share this answer
 
Thanks everyone,

Actually its update panel which is making the problem.

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900