Intersoft WebDesktop Documentation
Programmatically refresh server control
Send Feedback
Intersoft WebDesktop > WebFlyPostBackManager > Tutorials > Programmatically refresh server control

Glossary Item Box

Objectives

This tutorial demonstrates how to refresh server control programmatically without causing full page postback.

  1. Drag two DropDownList controls into the WebForm and name them ddlMake and ddlModel.

  2. Drag WebFlyPostBackManager from Toolbox into a WebForm page.



  3. In code behind, add the following code.

    C# Copy Code
    using ISNet.WebUI.WebDesktop;
    
    public partial class ProgrammaticallyRefresh : System.Web.UI.Page
    {
    WebFlyPostBackListener listener = null;
        protected void Page_Load(object sender, EventArgs e)
    {
    body.Style.Add("overflow", "hidden");
    listener = new WebFlyPostBackListener(this);
    }
    }

  4. Add some items to ddlMake.



  5. Add a method to populate data for ddlModel based on the value of ddlMake. Note that you must add WebFlyPostBackMethod() attribute so that the method can be included in the Metadata collection.

    C# Copy Code
    [WebFlyPostBackMethod()]
    public void PopulateModel()
    {    
       ddlModel.Items.Clear();    
       if (ddlMake.Text != "- Select a Make -")    
       {        
          for (int i = 1; i <= 5; i++)            
             ddlModel.Items.Add(new ListItem(ddlMake.Text + " Model " + i.ToString(), i.ToString()));    
       }    
       ddlMake.SelectedIndex = 1;     
    
       WebFlyPostBackManager1.ClientAction.UpdateViewState();     
       WebFlyPostBackManager1.ClientAction.RenderControl(ddlModel);
    }
    

  6. Add onchange event for ddlMake to call PopulateModel method from client side using WebFlyPostBackManager.

    Script Copy Code
    <script language="javascript">
    function PopulateModel()
    {
    var fpb = ISGetObject("WebFlyPostBackManager1");
    fpb.PopulateModel();
    }
    </script>

  7. Set the following properties of WebFlyPostBackManager.
    Properties Values
    ServiceType WebForm
    ServiceUrl The URL path of the page (in this case, the path is ~/test/ProgrammaticallyRefresh.aspx)
    PostInputControls True
    PostViewState True



  8. Run the page. Select a value from ddlMake and data will be populated in ddlModel without causing full page postback.

© 2012 Intersoft Solutions Corp. All Rights Reserved.