views:

513

answers:

1

Hi all,

We are using YUI library in our asp.net project. I have a asp.net autopostback dropdown list which is converted to YUI dropdownlist as the code shown below. Now when user select some value from the dropdownlist the page posts back and the SelectedGroupChanged event fires but before that the confirm dialog box is not appearing. What I could be doing wrong here?

Code:

    <asp:Button id="Groups" Enabled="false" runat="server" />
<asp:DropDownList ID="groupsDropDownList" runat="server" AutoPostBack="true" OnSelectedIndexChanged="SelectedGroupChanged" />

<script language="javascript" type="text/javascript">

var YUIGroupsDrpDown;

<%if (Groups.Visible)

{ %>
    YUIGroupsDrpDown = new YAHOO.widget.Button("<%=Groups.ClientID %>",{type:"menu", menu: "<%=groupsDropDownList.ClientID %>"});
    YUIGroupsDrpDown.set("label", "<%=groupsDropDownList.SelectedItem.Text%>" );
    YUIGroupsDrpDown.getMenu().subscribe("click",onGroupsChange);
    YUIGroupsDrpDown.on("click", {fn: TakeActions, obj: 'M'});
<%} %>

function onGroupsChange()
{

   YUIGroupsDrpDown.set("label", YUIGroupsDrpDown.getMenu().activeItem.srcElement.text );

}


function TakeActions(event, action)

{
    var message = 'some message'
        if (window.confirm(strMsg) != 1)
            return false;
        else
            return true;

}

A: 

Finally I found the answer. Actually YUI is wiring its own submit event to the form for the autopostback dropdownlist. So we need to prevent these YUI event if user chooses to cancel his action. So to do this, here's the code that I got from the YUI's example page:

var onExampleSubmit = function(p_oEvent) {

      var bSubmit = 
        window.confirm("Are you sure you want to submit?")

      if(!bSubmit) {
       YAHOO.util.Event.preventDefault(p_oEvent);
      }

     };

        YAHOO.util.Event.on(pageForm, "submit", onExampleSubmit);

Hope this will help anybody who is using autopostback dropdownlist with a client side confirm message in asp.net.

24x7Programmer