Hello all,
Thanks for looking at my post and thank to anyone that provides me with the help I am looking for.
I dynamically load user controls from a default page but when a postback fires within the user controls I can’t get the selected user control to reload. Hard to explain so I will try to show you what is going on.
Default1.aspx
Default1.aspx.v b
When I click on the link “Say Hello” the user control “Hello.asc x” does load in the placeholder just fine.
Hello.ascx
Hello.ascx.vb
When I enter my name and click the “Answer” button the page reloads back to the original state with no user control loaded. Why is the “Hello.asc x” user control not loaded with “Lable1” populated with the information for the click event from the code behind event?
Can someone tell me why?
Thanks,
CroCrew~
Thanks for looking at my post and thank to anyone that provides me with the help I am looking for.
I dynamically load user controls from a default page but when a postback fires within the user controls I can’t get the selected user control to reload. Hard to explain so I will try to show you what is going on.
Default1.aspx
Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default1.aspx.vb" Inherits="Default1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:PlaceHolder runat="server" ID="myPlaceHolder">
Welcome please select a option.
</asp:PlaceHolder>
<p>
<asp:LinkButton id="LinkButton1" runat="server">Say Hello</asp:LinkButton><br />
<asp:LinkButton id="LinkButton2" runat="server">Say Goodbye</asp:LinkButton><br />
</p>
</form>
</body>
</html>
Code:
Partial Class Default1
Inherits System.Web.UI.Page
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
myPlaceHolder.Controls.Clear()
myPlaceHolder.Controls.Add(LoadControl("Hello.ascx"))
End Sub
Protected Sub LinkButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton2.Click
myPlaceHolder.Controls.Clear()
myPlaceHolder.Controls.Add(LoadControl("Goodbye.ascx"))
End Sub
End Class
Hello.ascx
Code:
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="Hello.ascx.vb" Inherits="Hello" %> What is your name? <asp:TextBox ID="TextBox1" runat="server"/> <asp:Button ID="Button1" runat="server" Text="Answer" /> <br /> <br /> <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
Code:
Partial Class Hello
Inherits System.Web.UI.UserControl
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = "Hello " & TextBox1.Text
End Sub
End Class
Can someone tell me why?
Thanks,
CroCrew~
Comment