ComponentOne Window for ASP.NET AJAX: Window for ASP.NET AJAX Top Tips

Window for ASP.NET AJAX Top Tips

The following tips were compiled from frequently asked user questions posted in the ComponentOne Studio for ASP.NET AJAX’s online forum.

Tip 1: Showing and hiding he window from postback

When a postback is raised from within a C1Window, you want to hide the window immediately after handling the postback. Two UpdatePanels, namely Content and Status Panel, are embedded in C1Window. As a result, any postback raised within is an asynchronous one. So to hide the C1Window immediately after the postback you could use ScriptManager in the handler method to register some scripts after the postback is finished. For example:

      Visual Basic

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

  ' other operation

  …

  ' close window after content is updated

Dim clientID As String = C1Window1.ClientID

ScriptManager.RegisterClientScriptBlock(Me, Me.[GetType](), "scriptKey", String.Format("$find('{0}').hide()", clientID), True)

End Sub

      C#

protected void Button1_Click(object sender, EventArgs e)

{

  // other operation

  …

  // close window after content is updated

string clientID = C1Window1.ClientID;

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "scriptKey", string.Format("$find('{0}').hide()", clientID), true);

}

Tip 2: Centering the window on the page

To center a C1Window control on the page, you could set properties as in the following example:

      Visual Basic

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    C1Window1.StartPosition = C1WindowPosition.Page

    C1Window1.HorizontalAlign = HorizontalPosition.Center

    C1Window1.VerticalAlign = VerticalPosition.Middle

End Sub

      C#

protected void Page_Load(object sender, EventArgs e)

{

    C1Window1.StartPosition = C1WindowPosition.Page;

    C1Window1.HorizontalAlign = HorizontalPosition.Center;

    C1Window1.VerticalAlign = VerticalPosition.Middle;

}

Tip 3: Embedding a external page in the window

To embed an external page in C1Window, you could set the ContentUrl property. For example:

      Visual Basic

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    C1Window1.ContentUrl = "http://www.msn.com"

End Sub

      C#

protected void Page_Load(object sender, EventArgs e)

{

    C1Window1.ContentUrl = "http://www.msn.com";

}

If you already have content in the content template of C1Window you could switch between the frame and content view by using the setUpdatePanel and setUrl client-side methods. The client side reload method could be used to refresh the external page.

Tip 4: Setting the caption bar icon

You can add and customize the icon that appears in the C1Window caption bar. For example, the following code sets and the image and image size:

      Visual Basic

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    ' set icon to visible

    C1Window1.CaptionButtons.Icon.Visible = True

    ' set icon path

    C1Window1.ImageUrl = "~/Images/copy.gif"

    ' set icon size

    C1Window1.ImageHeight = 15

    C1Window1.ImageWidth = 15

End Sub

      C#

protected void Page_Load(object sender, EventArgs e)

{

    // set icon to visible

    C1Window1.CaptionButtons.Icon.Visible = true;

    // set icon path

    C1Window1.ImageUrl = "~/Images/copy.gif";

    // set icon size

    C1Window1.ImageHeight = 15;

    C1Window1.ImageWidth = 15;

}

Tip 5: Setting window resizing options

The resizing behavior of C1Window can be changed by setting children properties in ResizeSettings. For example, by default C1Window resizes with a resizing proxy. You can change the behavior by setting resizing properties with the following code:

      Visual Basic

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    ' no proxy

    C1Window1.ResizeSettings.UseHelper = False

    ' set minimum height and width of C1Window

    C1Window1.ResizeSettings.MinHeight = 100

    C1Window1.ResizeSettings.MinWidth = 300

End Sub

      C#

protected void Page_Load(object sender, EventArgs e)

{

    // no proxy

    C1Window1.ResizeSettings.UseHelper = false;

    // set minimum height and width of C1Window

    C1Window1.ResizeSettings.MinHeight = 100;

    C1Window1.ResizeSettings.MinWidth = 300;

}

Tip 6: Hiding the window on pressing ESC button

C1Window can be closed when the user presses ESC button at run time. You can implement this option by setting the OnEscPressedClose property to True:

      Visual Basic

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    C1Window1.OnEscPressedClose = True

End Sub

      C#

protected void Page_Load(object sender, EventArgs e)

{

    C1Window1.OnEscPressedClose = true;

}


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.