开发者

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 s开发者_如何学Cet 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 :)


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜