DefaultButton in UpdatePanel

Last post 05-22-2008 11:54 AM by mpk1212. 24 replies.

Sort Posts:

  • DefaultButton in UpdatePanel

    03-16-2006, 6:34 AM
    • Member
      138 point Member
    • Marinus
    • Member since 03-16-2006, 11:21 AM
    • Posts 38

    ASP.Net 2.0 has a nice feature. You can - in a panel - define a DefaultButton. When you have focus in a TextBox (on the panel) and presses RETURN, you click the DefaultButon.
    When using an UpdatePanel (ScriptManager:EnablePartialRendering="True this also works fine, but... only once.  
    Does somebody knows a workaround or a solution or am I doing something wrong?

    <atlas:UpdatePanel ID="UpdatePanel1" runat="server">
      <ContentTemplate>
        <asp:Panel ID="Panel1" runat="server" DefaultButton="Button1">
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" OnClientClick='alert("click")' Text="Button" /></asp:Panel>
      </ContentTemplate>
    </atlas:UpdatePanel>

  • Re: DefaultButton in UpdatePanel

    03-16-2006, 8:03 AM
    • All-Star
      25,662 point All-Star
    • Luis Abreu
    • Member since 02-12-2005, 6:22 AM
    • Madeira [Portugal]
    • Posts 5,368
    • TrustedFriends-MVPs
    hello.

    well, this is a side-effect bug related with the way the code used by the asp.net works. when you add a default button, you get this on your panel:



    THe problem happens on the WebForm_firedDefaultButton. Inside, the method checks for a global variable called __defaultFired which initially is set to false. the 1st thing the method does is check the value of this var. if it is set to true, it doesn't do anything since it thinks you're re-submitting the form. if you think only about ASP.NET, this makes sense, right?

    unfortunatelly, when yuo use atlas you start getting the behavior you've described. for now, i think that you can override the prerender method of your page and add this:

    protected override void OnPreRender (EventArgs args)
    {
    base.OnPreRender(args);
    this.ClientScript.RegisterStartupScript(this.GetType(), "resetBt", "__defaultFired = false;", true);
    }

    By injecting this instruction, you're resetting the state of the _defaultFired variable so that you're able to start another request when you press the enter key.
    --
    Regards,
    Luis Abreu
    email: labreu_at_gmail.com
    EN blog:http://msmvps.com/blogs/luisabreu
  • Re: DefaultButton in UpdatePanel

    03-16-2006, 8:21 AM
    • All-Star
      25,662 point All-Star
    • Luis Abreu
    • Member since 02-12-2005, 6:22 AM
    • Madeira [Portugal]
    • Posts 5,368
    • TrustedFriends-MVPs
    btw, what's wrong with the feedback center? i'm trying to add a bug and can't pass from the searh page :(
    --
    Regards,
    Luis Abreu
    email: labreu_at_gmail.com
    EN blog:http://msmvps.com/blogs/luisabreu
  • Re: DefaultButton in UpdatePanel

    03-16-2006, 9:14 AM
    • Member
      138 point Member
    • Marinus
    • Member since 03-16-2006, 11:21 AM
    • Posts 38

    Thank you for your reply Luis. It works!

  • Re: DefaultButton in UpdatePanel

    08-25-2006, 12:38 PM
    • Member
      76 point Member
    • tarzaan
    • Member since 08-17-2006, 12:18 PM
    • Posts 23
    Sorry to say but then i am having the same problem and not bale to get it work :(

    Can you please help ???
  • Re: DefaultButton in UpdatePanel

    10-09-2006, 9:53 PM
    • Contributor
      5,555 point Contributor
    • Eilon
    • Member since 06-26-2002, 2:14 PM
    • Redmond, WA
    • Posts 951
    • AspNetTeam

    This is a known issue in the current CTP and we are considering fixing it in a future release.

    Thanks,

    Eilon

    Blog: http://weblogs.asp.net/LeftSlipper/
  • Re: DefaultButton in UpdatePanel

    10-17-2006, 6:25 AM
    • Member
      65 point Member
    • fduffner
    • Member since 01-17-2006, 1:49 PM
    • Posts 13

    the prerender solution doesn't work at my neither :(

    maybe it depends on which CTP you're using? are there any other solutions available right now?

  • Re: DefaultButton in UpdatePanel

    10-17-2006, 9:03 AM
    • Member
      65 point Member
    • fduffner
    • Member since 01-17-2006, 1:49 PM
    • Posts 13

      protected override void OnPreRender(EventArgs args)
      {
        base.OnPreRender(args);
        this.ClientScript.RegisterStartupScript(this.GetType(), "resetBt", "__defaultFired = false;", true);
      }

     

    works in IE but not in Firefox

    always working Workaround or Fix would be great
     

  • Re: DefaultButton in UpdatePanel

    11-17-2006, 12:03 PM
    • Member
      12 point Member
    • mwilson71
    • Member since 10-31-2006, 9:57 AM
    • Posts 4

    Does anyone have a workaround for this that will work in Firefox?  I'd really rather not have to yank out all of my updatepanels, but this is about the only option I see right now. 

    Thanks

  • Re: DefaultButton in UpdatePanel

    11-17-2006, 12:34 PM
    • All-Star
      25,662 point All-Star
    • Luis Abreu
    • Member since 02-12-2005, 6:22 AM
    • Madeira [Portugal]
    • Posts 5,368
    • TrustedFriends-MVPs

    hello.

    i really hanve't checked how the current version implements this functionality. i suggest that you use a new static methods of the scriptmanager class instead of using the clientscriptmanager class to register the startup scripts.

    --
    Regards,
    Luis Abreu
    email: labreu_at_gmail.com
    EN blog:http://msmvps.com/blogs/luisabreu
  • Re: DefaultButton in UpdatePanel

    12-03-2006, 2:17 AM
    • Member
      130 point Member
    • fhirzall
    • Member since 05-03-2006, 5:06 AM
    • Posts 44

    Has anyone figured out a way to get the the default button working with firefox in an updatepanel?

    Did'nt want to start a new topic!

     Thanks

  • Re: DefaultButton in UpdatePanel

    12-03-2006, 7:55 AM
    • All-Star
      25,662 point All-Star
    • Luis Abreu
    • Member since 02-12-2005, 6:22 AM
    • Madeira [Portugal]
    • Posts 5,368
    • TrustedFriends-MVPs
    hello.

    if i recall correctly, the approach mentioned on this thread doesn't work only in IE (ie, it should work without any problems in firefox)
    --
    Regards,
    Luis Abreu
    email: labreu_at_gmail.com
    EN blog:http://msmvps.com/blogs/luisabreu
  • Re: DefaultButton in UpdatePanel

    12-03-2006, 12:00 PM
    • Member
      365 point Member
    • dblock
    • Member since 12-06-2005, 12:33 PM
    • New York
    • Posts 95

    After struggling with this for a while between browsers and Atlas ajax.net I chose a dumb method and implement this in code, w/o using the DefaultButton attribute. I set this on Page_Load for any control collection. In fact ASP.NET should have  a default button setting for just about anything that is clickable - for example the button on an panel extender.

    public static void SetDefaultButton(WebControl button, ControlCollection cc)
    {
     foreach (System.Web.UI.Control wc in cc)
     {
      SetDefaultButton(button, wc.Controls);
     
    if (wc is System.Web.UI.WebControls.WebControl)
     
    {
      
    if (wc is System.Web.UI.WebControls.TextBox)
       {
       
    TextBox tb = (TextBox)wc;
        SetDefaultButton(button, tb);
       }
    }}}

    public static void SetDefaultButton(WebControl button, TextBox tb)
    {
     
    if (tb.TextMode == TextBoxMode.MultiLine)
     
    return;

     tb.Attributes.Add(

    "onkeydown","if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + button.UniqueID + "').click();return false;}} else {return true}; ");
    }

     

    dB. - www.dblock.org / www.foodcandy.com
  • Re: DefaultButton in UpdatePanel

    12-13-2006, 3:07 PM
    • Member
      point Member
    • lgoodell
    • Member since 12-13-2006, 7:50 PM
    • Posts 3

    The OnPrerender() solution above didn't work for my app.

    I had this issue in IE and Firefox. In IE the first time the user pressed enter the default button fired, but after that it won't fire. In FireFox is was just the opposite, the first time it wouldn't fire and then it fired fine after that.

    The fix I came up with (after seeing the OnPrerender() exmaple) is to set the __defaultFired variable appropriately in the pageLoad() function which AJAX calls after the page is completely loaded. This works for IE, Firefox and Safari.

    <script type="text/javascript" language="javascript">
       function pageLoad()
       {
          if (navigator.userAgent.indexOf("Firefox")!=-1)
          {
             __defaultFired = true;
          }
          else
          {
             __defaultFired = false;
          }
       }
    </script>

    I put this on my master page and now all my default buttons fire properly now.

    Anyone know why Firefox has the reverse logic for __defaultFired???

     

  • Re: DefaultButton in UpdatePanel

    12-27-2006, 11:55 AM
    • Member
      133 point Member
    • GremlinX
    • Member since 03-07-2006, 7:20 PM
    • Canada
    • Posts 35

    I am having the same problem.  :(  DefaultButton works only in IE, not in Firefox.  Can anyone on the Asp.net Ajax team comment on whether this will be fixed for the release version?

    Thanks

    Binary Fortress Software
    http://www.binaryfortress.com
Page 1 of 2 (25 items) 1 2 Next >