开发者

Set updatepanelanimationextender TargetControId at codebehind

Inside usercontrol I have updatepanelanimationextender, when I add this control to a webpage I want to pass updatepanel's Id as parameter to control's property.

Usercontrol:

public partial class Controls_UpdateProgress : System.Web.UI.UserControl
{ 
    public string UpdatePanelID { get; set; }
    protected void Page_Load(object sender, EventArgs e)
    {     
        if (!IsPostBack)
        {
            UpdatePanelAnimationExtender1.TargetControlID = UpdatePanelID;              
        }

    }
}

<cc1:updatepanelanimationextender id="UpdatePanelAnimationExtender1" runat="server" >
            <Animations>
               <OnUpdating>
                   <Parallel duration="0" >        
                       <ScriptAction Script="onUpdating();" />  
                   </Parallel>
               </OnUpdating>
                 <OnUpdated>
                  <Parallel duration="0">             
                     <ScriptAction  Script="onUpdated();"  /> 
                  </Parallel> 
               </OnUpdated>
            </Animations>
        </cc1:updatepanelanimationextender>

WebPage: UpdatePanel1 is an id of the updatepanel.

<uc1:UpdateProgress ID="UpdateProgress1" runat="server" UpdatePanelID="UpdatePanel1"    />

I get error:

The TargetControlID of 'UpdatePanelAnimationExtender1' is not 开发者_Python百科 valid. The value cannot be null or empty.


The AJAX control extenders do not store their TargetControlID in the ViewState (I checked in System.Web.Extensions 3.5 with Reflector and that property only gets/sets a private member). Thus, the value you stored is lost on postback.

You'll have to store the value in every request:

protected void Page_Load(object sender, EventArgs e)
{     
    UpdatePanelAnimationExtender1.TargetControlID = UpdatePanelID;              
}


To avoid that exception, you should first make sure that UpdatePanelID is not null...

if (!IsPostBack)         { 
     if (UpdatePanelID != Null) { 
            UpdatePanelAnimationExtender1.TargetControlID = UpdatePanelID;
     }
}

If you desire to set the property of the UpdatePanelID from the parent page programmatically you will need to cast UpdateProgress1 as a Controls_UpdateProgress instance. To do that, do something like this...

((Controls_UpdateProgress)UpdateProgress1).UpdatePanelID = "ThisIsTheIdYouWishToSet";
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜