Thursday, February 3, 2011

Default Form Button in FireFox

I am building a server control that will search our db and return results. The server control is contains an ASP:Panel. I have set the default button on the panel equal to my button id and have set the form default button equal to my button id.

On the Panel:

 MyPanel.DefaultButton = SearchButton.ID

On the Control:

Me.Page.Form.DefaultButton = SearchButton.UniqueID 

Works fine in IE & Safari I can type a search term and hit the enter key and it searches fine. If I do it in FireFox I get an alert box saying "Object reference not set to an instance of an a object.

Anyone run across this before?

  • Is SearchButton a LinkButton? If so, the javascript that is written to the browser doesn't work properly.

    Here is a good blog post explaining the issue and how to solve it:

    Using Panel.DefaultButton property with LinkButton control in ASP.NET

    From Otto
  • I might be wrong and this might not make a difference but have you tried:

    Me.Page.Form.DefaultButton = SearchButton.ID

    instead of

    Me.Page.Form.DefaultButton = SearchButton.UniqueID
    From Bryan Roth
  • @Otto - SearchButton is not a LinkButton, it's regular old fashioned button.

    @Bryan Roth - Yes, in fact that's what I first tried - it doesn't compile if you don't use UniqueID - I was getting this error

    From brendan
  • Ends up this resolved my issue:

         SearchButton.UseSubmitBehavior = False
    
    From brendan
  • Brendan with JS disabled using UseSubmitBehaviour="false" the form will not post back? I agree with otto and also wrote a post about this a while ago and how to allow to forms to work within a page (using two forms requires JS though!) c# Default buttons

    From Tim

0 comments:

Post a Comment