Larry Brister
asked on
ASP.NET
I have a usercontrol (login.ascx) that gets loaded through the masterpage on load.
There's a submit button on it that I need to make the default button when someone doesn't click on it but just hits the <ENTER> key. I know I can do that on an ASPX page...but how in a user control?
Thanks
There's a submit button on it that I need to make the default button when someone doesn't click on it but just hits the <ENTER> key. I know I can do that on an ASPX page...but how in a user control?
Thanks
ASKER
samtram0331,
Trying to figure out why this doesn't work...
Trying to figure out why this doesn't work...
Select Case CStr(Request.Params("page"))
Case "home"
Session("info") = " Home Page"
Dim uc As UserControl = CType(LoadControl("includes/login.ascx"), UserControl)
Dim btn As Button = CType(uc.FindControl("ImageButton1"), Button)
ContentPlaceHolder1.Controls.Add(uc)
Me.form1.DefaultButton = btn.ID
uc.ID = "uc1"
it looks like you're trying to convert an image button to a button....try changing the line:
Dim btn As Button = CType(uc.FindControl("Imag eButton1") , Button)
to
Dim btn As ImageButton = CType(uc.FindControl("Imag eButton1") , ImageButton)
Dim btn As Button = CType(uc.FindControl("Imag
to
Dim btn As ImageButton = CType(uc.FindControl("Imag
ASKER
samtram...It forced me to use the IButton code..below. But when I load that I'm getting the error message in the attached snippet
Session("info") = "Home Page"
Dim uc As UserControl = CType(LoadControl("include s/login.as cx"), UserControl)
Dim btn As IButtonControl = CType(uc.FindControl("Imag eButton1") , IButtonControl)
ContentPlaceHolder1.Contro ls.Add(uc)
Me.form1.DefaultButton = btn
uc.ID = "uc99"
Session("info") = "Home Page"
Dim uc As UserControl = CType(LoadControl("include
Dim btn As IButtonControl = CType(uc.FindControl("Imag
ContentPlaceHolder1.Contro
Me.form1.DefaultButton = btn
uc.ID = "uc99"
Unable to cast object of type 'System.Web.UI.WebControls.ImageButton' to type 'System.String'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Web.UI.WebControls.ImageButton' to type 'System.String'.
Source Error:
Line 176: Dim btn As IButtonControl = CType(uc.FindControl("ImageButton1"), IButtonControl)
Line 177: ContentPlaceHolder1.Controls.Add(uc)
Line 178: Me.form1.DefaultButton = btn
Line 179: uc.ID = "uc99"
Line 180: End Select
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Page_Load is on the master page.
My test user control has a button named "Button1", which I'm setting as the default button on the master page:
Open in new window