<%@ Master Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ctrl As Control = LoadControl("ucDefaultButton.ascx")
Dim btn As Button = CType(ctrl.FindControl("Button1"), Button)
Me.ContentPlaceHolder1.Controls.Add(ctrl)
Me.form1.DefaultButton = btn.ID
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server" defaultbutton="Button1">
<div>
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>
</html>
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"
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
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
From novice to tech pro — start learning today.
Open in new window