dimanche 28 juin 2015

UpdatePanel with Asyncpostback trys to load control outside updatepanel

I need to have UpdatePanel with asyncpostback, but in my case it seems that no partial postback happens, but fullpostback. I am new to web forms, please, check the code:

<%@ Register TagPrefix="Cust" TagName="CompanyInformationView" Src="~/CustomControls/CompanyInformationView.ascx" %>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
    <asp:UpdatePanel runat="server" ID="UpdatePanel1" ChildrenAsTriggers="true" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:Button ID="Button1" runat="server" OnClick= "Button1_Click" Text="test" />
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>

    <Cust:CompanyInformationView ID="CompanyInformationView" runat="server" />   
</asp:Content>

So I have Test Button. OnClick it should do "nothing" for test. Also there is custom control on web form. Here is server side code for this form:

protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // fill in custom control CompanyInfo c = GetInfo(); CompanyInformationView.Company = c; } }

protected void Button1_Click(object sender, EventArgs e)
{
    var i = 1;
}

CompanyInformationView is custom control with property "Company". There is no ViewState added for this property (so it cannot be loaded properly if postback is done). When I click on Test Button, the page fails, because "CompanyInformationView.Company" is not set (it is not set, because it cannot be loaded from ViewState, I guess).

Instead, I think that it should not work like this. AsynPostback should deal only with UpdatePanel.

Why it wants to reload custom control? Doesn't it mean that Full postback happen or maybe I do not understand Asyncpostback?

Aucun commentaire:

Enregistrer un commentaire