Udi I
Udi I

Reputation: 1

ASP.NET Controls after postback

I have a web page which consists a few asp:buttons, asp:textbox, gridview and asp:imagebutton.

When the Page loads for the first time, the user insert a number into the textbox, and then presses the button which preform the postback.

My question is that : after the postback in the page_load event I have a refrence to the imagebutton, i can set its display etc.

As apart of the postback, the gridview is being updated, i call gridview.databind() from the page_load so the gridview selecting event is triggred, but when i try to refernce the imagebutton from whithin the selecting method i see that the imagebutton is null.

If i will try to refrence that imagebutton again from the page_load, after the selecting method is completed, there is no problem.

Why cant I reference the imagebutton, or actually any other control, from the selecting method ?

10X alot :)

Upvotes: 0

Views: 427

Answers (2)

Zo Has
Zo Has

Reputation: 13018

Because you are using page load for both postback and pageLoad() Try using if(!Page.IsPostBack) { //your code } for setting initial controls

Upvotes: 1

Chase Florell
Chase Florell

Reputation: 47367

If I'm reading your question properly, on your Page_Load you need to do something like this

public void Page_Load()
{
    if (!Page.IsPostBack) {
        //Do your initial binding for the image
    }
}

Then in your button event you can rebind the image to whatever new image you like

Upvotes: 0

Related Questions