Connecting Tech Pros Worldwide Forums | Help | Site Map

Postback not working

CroCrew's Avatar
Expert
 
Join Date: Jan 2008
Location: Michigan
Posts: 338
#1: 4 Weeks Ago
I know that I should post my question in the asp.net forum but I did not want just anyone to answer my question. I want just the “Pros” answers. First off; I don’t want to use master pages. I hate them! Second I want to that everyone that posts a reply to this question in advance.

I have three “user controls” and on page (see below). The steps that I am trying to do and will not give up on till I get a solution. Everything is possible; just trying to rig it to work is the test.

Walk through: The “Default.aspx” page loads and within that page there are two “PlaceHolder”s. Both are pre-populated with a link (PlaceHolder01) and text (PlaceHolder02). When the link within “PlaceHolder01” (Link One) is clicked; on the postback “PlaceHolder01” gets a new user control injected within it and the verbage for “PlaceHolder01” is now “Link Two”. All this works so far.

Here is where the problem starts:

When you click on “Link Two” within “PlaceHolder01” the postback should change the value within “PlaceHolder02” with another user control. But it does not.

Anyone knows why? Or has a work around?

Thanks,
CroCrew~

Default.aspx
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4.     <head runat="server">
  5.         <title></title>
  6.     </head>
  7.     <body>
  8.         <form id="form1" runat="server">
  9.             <div>
  10.                 Links:
  11.                 <asp:PlaceHolder runat="server" ID="PlaceHolder01">
  12.                     <a href="#" id="btnLinkOne" runat="server">Link One</a>
  13.                 </asp:PlaceHolder>
  14.                 <br />
  15.                 <br />
  16.                 <br />
  17.                 <br />
  18.                 Body:
  19.                 <asp:PlaceHolder runat="server" ID="PlaceHolder02">
  20.                     Welcome!
  21.                 </asp:PlaceHolder>    
  22.             </div>
  23.         </form>
  24.     </body>
  25. </html>
  26.  
Default.aspx.vb
Expand|Select|Wrap|Line Numbers
  1. Partial Class _Default
  2.     Inherits System.Web.UI.Page
  3.  
  4.     Protected Sub btnLinkOne_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLinkOne.ServerClick
  5.         btnLinkOne.Controls.Clear()
  6.         btnLinkOne.Controls.Add(LoadControl("WebUserControl.ascx"))
  7.     End Sub
  8. End Class
  9.  
WebUserControl.ascx
Expand|Select|Wrap|Line Numbers
  1. <%@ Control Language="VB" AutoEventWireup="false" CodeFile="WebUserControl.ascx.vb" Inherits="WebUserControl" %>
  2. <a href="#" id="btnLinkTwo" runat="server">Link Two</a>
  3.  
WebUserControl.ascx.vb
Expand|Select|Wrap|Line Numbers
  1. Partial Class WebUserControl
  2.     Inherits System.Web.UI.UserControl
  3.  
  4.     Protected Sub btnLinkTwo_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLinkTwo.ServerClick
  5.         Page.FindControl("PlaceHolder02").Controls.Clear()
  6.         Page.FindControl("PlaceHolder02").Controls.Add(LoadControl("WebUserControl2.ascx"))
  7.     End Sub
  8. End Class
  9.  
WebUserControl2.ascx
Expand|Select|Wrap|Line Numbers
  1. <%@ Control Language="VB" AutoEventWireup="false" CodeFile="WebUserControl2.ascx.vb" Inherits="WebUserControl2" %>
  2. <b>Cool!!</b>
  3.  
best answer - posted by Frinavale
You have 2 user controls:
  • WebUserControl
  • WebUserControl2

They are related to one another.
You have stated that the Default.aspx page should manage of how they interact....

To do this I recommend using Events.

When the user clicks link2 in WebUserControl raise an event (maybe call it something like LinkClicked or something).

Implement a method that handles that event in your Default.aspx page which displays WebUserControl2.

-Frinny

CroCrew's Avatar
Expert
 
Join Date: Jan 2008
Location: Michigan
Posts: 338
#2: 4 Weeks Ago

re: Postback not working


More information…

I just stepped through the code and when the btnLinkTwo link is click it never goes into the btnLinkTwo_ServerClick Protected Sub.

I did put a Page_Load event on WebUserControl.ascx.vb to see if the code behind page works and it did go into that sub.

Thanks again for any help,
CroCrew~
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,181
#3: 4 Weeks Ago

re: Postback not working


You have 2 user controls:
  • WebUserControl
  • WebUserControl2

They are related to one another.
You have stated that the Default.aspx page should manage of how they interact....

To do this I recommend using Events.

When the user clicks link2 in WebUserControl raise an event (maybe call it something like LinkClicked or something).

Implement a method that handles that event in your Default.aspx page which displays WebUserControl2.

-Frinny
Reply


Similar ASP.NET bytes