Question : Default buton of login control in usercontrol

Hello, I have a login control that resides in a web user control. I want to set the parent pages default button to that of the login control.
This is what I have so far but get an Object reference not set to an instance of an object error message on this line:

Page.Form.DefaultButton = button.UniqueID
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then

            Dim login As UserControl = DirectCast(Me.FindControl("ctlLogin"), UserControl)
            login.Focus()
            Dim button As Button = DirectCast(login.Parent.FindControl("LoginButton"), Button)

            Page.Form.DefaultButton = button.UniqueID
                
        End If
    End Sub

Answer : Default buton of login control in usercontrol

Page.Form.DefaultButton = button.ClientID
ClientId instead of uniqueid....
Random Solutions  
 
programming4us programming4us