asp.netdefaultbuttonmaster-pages

How to avoid InvalidOperationException when setting the defaultbutton in ASPX content


I am trying to set a default button in my ASPX page. I have a master page so the form is there. I have a panel in the content page that holds a table that organizes a number of textboxes, dropdowns and other inputs. The last row of the table holds some buttons, one of which I want to be the default button. After doing some research, I have tried the following with no success.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not IsPostBack Then
       pnlHolder.DefaultButton = cmdSearchJob.ClientID

I have also tried

pnlHolder.DefaultButton = cmdSearchJob.UniqueID

and

Dim cmdDef As Button = pnlHolder.FindControl("cmdSearchJob")
pnlHolder.DefaultButton = cmdDef.UniqueID

but both throw the exception "The DefaultButton of 'pnlHolder' must be the ID of a control of type IButtonControl.".

I have seen some Javascript solutions, but was hoping to just be able to set the defaultButton for the panel.


Solution

  • Finally found what it was. Tried adding another button with no CSS, etc. that just popped up a javacsript alert() for testing. Was able to set that as the default button when it was outside the table. As the submit button is one of a series of buttons (not a very pretty UI, but user requirements and all that) in the table, I used this additional button and set its style to display:none and have it call the same subroutine in the code behind.

    So, short answer, it wasn't seeing it in the table.

    Thanks everyone for your input.

    I still have no idea why it wouldn't set the button.