Welcome Guest Search | Active Topics | Sign In | Register

Dialog control assistance Options
Darren Brennan
Posted: Wednesday, February 25, 2009 10:37:06 AM
Rank: Newbie
Groups: Member

Joined: 2/25/2009
Posts: 3
Hi guys, hoping you can assist me.

I am evaluating your controls for a major project I am working on. Having a little difficulty with getting the AcceptButton event handler to fire. Here is some pseudo code from the code behind which outlines the scenario:

Code: Visual Basic.NET
Try
    Access webservice
Catch
    Show modal dialog control (to warn if webservice is unavailable)
    Perform further actions after dialog is accepted
End Try


I have created an asp.net button in the footer template and included it's ID in the Dialog AcceptButton property.

What is happening is the further actions code is being run before the dialog is accepted. Specifically I want to set field focus on a textbox control after the dialog is accepted but this fails as the dialog still has focus when this code executes.

Here's some things I have tried:

1. Setting the AcceptButtonPostBack property to true but then the dialog doesn't disappear when the button is clicked.

2. Moving the further actions code to the button's click event handler but it doesn't seem to fire when the dialog button is clicked.

3. Displaying the dialog either server side through the InitialState property and also using the RegisterStartupScript to use the 'eo_GetObject(Dialog).show' function client side.

Am I missing something really obvious here? Hoping you can steer me in the right direction with this.

Many thanks

Darren


eo_support
Posted: Wednesday, February 25, 2009 10:53:43 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

In order to fire server event when a button is clicked, the easiest way is to clear AcceptButton property. Just put an asp:Button in the footer area and it should be all set. Once you click it, it should post back the page and fire your server side event handler. The dialog automatically closes itself out in such case.

If however inside your accept button's server side handler you need to re-display the dialog, you can simply set the dialog's InitialState back to Visible. You mentioned this does not work for you, we are not sure why. You may want to try this logic in a separate blank page to see if it has anything to do with other content in your page.

I also noticed that you have the following pseudo code:

Code:
step a. Show modal dialog control (to warn if webservice is unavailable)
step b. Perform further actions after dialog is accepted


I am not sure if you are only trying to describe what your scenario is or your actual code flow is like this. If you expect your actual code flow to be like this, then there appears to be a misunderstanding. The key is the dialog is never blocking, even for a modal dialog. It works this way:

1. Your code shows a modal dialog. This merely set a flag. The code does not block here;
2. Your code continues to run until the page finishes rendering and all contents are sent to the client side;
3. The browser shows the modal dialog. User clicks accept button;
4. Your accept button event handler is fired, now you continue to perform further actions after dialog is accepted;

As such step a and step b are almost always in different code blocks (functions/event handlers).

Hope this helps. Please feel free to let us know if you have any more questions.

Thanks!
Darren Brennan
Posted: Thursday, February 26, 2009 4:48:32 AM
Rank: Newbie
Groups: Member

Joined: 2/25/2009
Posts: 3
Hi there, thanks for your reply.

I followed your advice and cleared the AcceptButton property completely. When set like that, the dialog doesn't close at all and it doesn't appear to postback either. I dont think I've ever had it postback propertly. When the AcceptButton property is set to the button again, the dialog closes but it still doesn't trigger a postback. If I also set the AcceptButtonPostback property to true, again the dialog doesn't close at all and doesn't postback.

Apologises and I understand your point about the way I had written the pseudo code - it was just to show you what I was trying to achieve rather than me expecting the dialog to change the page life cycle. You're right about steps a and b being in different code blocks. One of the things I had tried was putting step b in the button's server side click event handler. I think because the dialog isn't posting back, this code is never firing.

However triggering the postback event from the button IS the behaviour I'm trying to achieve as I can catch the click event separately server side after the postback has occurred.

One thing I never mentioned on my first post is at the moment the dialog is part of a user control and other controls within this user control are using the MS AJAX extenders (watermark, validator callout etc). I had planned to use the dialog in a number of user controls similar to this. Do you think this could be a reason for what I am experiencing?

EDIT:

I have experimented further with this. Completely new page with basic button added to trigger the opening of the dialog.
Code: Visual Basic.NET
<eo:Dialog ID="AccountLookupDialog" runat="server" BorderStyle="Solid" BorderWidth="1px"
            BackShadeColor="LightGray" BackShadeOpacity="50" BorderColor="#728EB8" ControlSkinID="None"
            ShadowColor="LightGray" ShadowDepth="4" HeaderHtml="Savings Account Application Message"
            Height="120px" Width="268px" BackColor="White">
            <HeaderStyleActive CssText="padding-right: 10px; padding-left: 10px; font-size: 12px; font-weight: bold; background-image: url(00070202); padding-bottom: 2px; padding-top: 2px; font-family: arial" />
            <ContentStyleActive CssText="padding-right: 10px; padding-left: 10px; font-size: 11px; padding-bottom: 10px; padding-top: 10px; font-family: verdana; background-color: #f8fafd" />
            <FooterStyleActive CssText="padding-right: 10px; padding-left: 10px; font-size: 11px; padding-bottom: 10px; padding-top: 4px; font-family: verdana; background-color: #f8fafd" />
            <FooterTemplate>
                <asp:Button ID="AcceptButton" runat="server" Text="OK" />
            </FooterTemplate>
        </eo:Dialog>
        <asp:Button ID="Button3" runat="server" Text="Button" />


Code Behind Click Event Handler
Code: Visual Basic.NET
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click

        AccountLookupDialog.InitialState = EO.Web.DialogState.Visible
        AccountLookupDialog.ContentHtml = "Test"

    End Sub


In this example, there is nothing in the page_load event. When Button3 is clicked the dialog appears. When the AcceptButton is clicked it now DOES postback. However, rather than disappearing it reappears after postback.

I have also tried loading the dialog at first page_load with the usual If Not Page.IsPostback etc... Again when the AcceptButton is clicked it still reappears after postback. Its like it's ignoring the IsPostback property.

So now I am really at a loss on what to do next. Any ideas guys?

Many thanks
Darren
Darren Brennan
Posted: Thursday, February 26, 2009 7:51:44 AM
Rank: Newbie
Groups: Member

Joined: 2/25/2009
Posts: 3
Ok I appear to have resolved this issue. Bit of a gotcha and it is something really simple (these things always are!!).

It seems when using your dialog control alongside the MS AJAX extenders, any buttons that appear in the dialog box, must have the CausesValidation property explicitly set to False as otherwise it stops the dialog closing and triggers the client-side page validation instead.

Sorry for the long winded posts trying to get to the bottom of this but hopefully it may help others in the same situation.

Thanks

Darren
eo_support
Posted: Thursday, February 26, 2009 8:51:57 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi Darren,

Thank you very much for the update! This does make sense. All contents in the dialog still belong to the page so it does trigger all validation logic as if they were directly placed inside the page. As you have discovered, setting CausesValidation to false bypass this logic and allows the post back to proceed. I would expect setting ValidationGroup also work if you do need validation on the dialog contents.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.