CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 7/23/2004 9:27:00 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 2 Views: 70 Favorited: 0 Favorite
3 Items, 1 Pages 1 |< << Go >> >|
aspkahuna
Asp.Net User
Need help with Control Events in Page Template Archtitechture7/23/2004 9:27:00 PM

0

Hello all.
Thanks in advance. It has been at least 2 years since I have implemented my own PageTemplate. And I have it all working, my only problem is I cannot remeber how to handle the events for nested run-time created Child Controls.

IE. I can't remeber how to handle the event from the server controls within a DataGrid TemplateColumn ........

MyDataGrid_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles MyDataGrid.ItemCommand

All my top level events work, but it seems when the controls are in the PageTemplate, the event bubbling doesn't work or something. For the life of me I cannot remeber how I did it a couple years ago. Maybe delegates?? HAHA.

anyway let me lay down the situation:


The MasterTemplate is a USERCONTROL:

-----------------------------------------------------------------------------------------------------
ascx code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<title>
<%= me.Title %>
</title>
<LINK href="standard.css" type="text/css" rel="stylesheet">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:literal id="litHeader" Runat="server"></asp:literal><asp:placeholder id="BodyContainer" runat="server"></asp:placeholder><asp:literal id="litFooter" Runat="server"></asp:literal>
</form>
</body>
</HTML>

-----------------------------------------------------------------------------------------------------
ascx.vb:

<ParseChildren(True)> Public MustInherit Class MainTemplate
Inherits System.Web.UI.UserControl
'Implements INamingContainer

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub
Protected WithEvents BodyContainer As System.Web.UI.WebControls.PlaceHolder
Protected WithEvents litHeader As System.Web.UI.WebControls.Literal
Protected WithEvents litFooter As System.Web.UI.WebControls.Literal

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private _main As ITemplate
Private _title As String


Public Property body() As ITemplate
Get
Return Me._main
End Get
Set(ByVal Value As ITemplate)
Me._main = Value
End Set
End Property


Public Property Title() As String
Get
Return String.Format("Amerco Intranet: {0}", Me._title)
End Get
Set(ByVal Value As String)
Me._title = Value
End Set
End Property

Public Sub LoadChildControls()
Me.EnsureChildControls()
End Sub

Protected Overrides Sub CreateChildControls()
If Not body Is Nothing Then
body.InstantiateIn(BodyContainer)
End If
End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
If Request.IsAuthenticated Then
Dim UserGuid As String = context.User.Identity.Name

litHeader.Text = GetTheHeaderData(UserGuid)
litFooter.Text = GetTheFooterData(UserGuid)
Else
Response.Redirect("Login_main.aspx")
End If
End If
End Sub

End Class

-------------------------------------------------------------------------------------------------
That's the TemplateControl, pretty basic and easy. The problem resides in the pages


TESTPAGE .ASPX

--------------------------------------------------------------------------------------------------
..aspx code

<%@ Register TagPrefix="Master" TagName="Template" Src="../Controls/MainTemplate.ascx"%>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="EditDealerStandards.aspx.vb" Inherits="DealerReports.EditDealerStandards"%>
<Master:Template Title="PageTemplateTest" id="PageTemplate" runat="server">
<BODY>

<table cellSpacing="0" cellPadding="3" width="600" align="center" border="0">
<tr align="center">
<td>
<table class="actiontable" cellSpacing="0" cellPadding="3" align="center" border="0">
<tr>
<td>Select District, MCO, or Routes to Edit</td>
</tr>
<tr>
<td><asp:dropdownlist id="ddlEdit" Runat="server">
<asp:ListItem Value="District" Selected="True">District</asp:ListItem>
<asp:ListItem Value="MCO">MCO</asp:ListItem>
<asp:ListItem Value="Route">Route</asp:ListItem>
</asp:dropdownlist>&nbsp;&nbsp;
<asp:button id="cmdGetData" Runat="server" Text="Go" Height="22"></asp:button></td>
</tr>
</table>
<br>
<br>
<asp:datagrid id="dgDealers" Runat="server" AllowSorting="True" CssClass="data_table" AutoGenerateColumns="False"
PageSize="20" PagerStyle-Mode="NumericPages" AllowPaging="True">
<AlternatingItemStyle CssClass="alternating_row"></AlternatingItemStyle>
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Font-Bold="True" VerticalAlign="Bottom" HorizontalAlign="Center" />
<Columns>
<asp:TemplateColumn HeaderText="New Standard">
<ItemTemplate>
<asp:TextBox ID="txtNewStandard" Runat="server" Width="50" Height="20"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Retrieve Previous">
<ItemTemplate>
<!--PROBLEM CHILD HERE!!!!!!!!! THE EVENT WONT BUBBLE --> <asp:LinkButton ID="lcmdRetrieve" Runat="server" CommandArgument="Retrieve">Retrieve</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid><br>
<asp:button id="cmdApplyChanges" Runat="server" Text="Apply New Standards"></asp:button><br>
</td>
</tr>
</table>

</BODY>
</Master:Template>

-----------------------------------------------------------------------------------
and finally, the aspx.vb

Public Class EditDealerStandards
Inherits AdminPageBase

Protected WithEvents dgDealers As System.Web.UI.WebControls.DataGrid
Protected WithEvents ddlEdit As System.Web.UI.WebControls.DropDownList
Protected WithEvents cmdApplyChanges As System.Web.UI.WebControls.Button
Protected WithEvents cmdGetData As System.Web.UI.WebControls.Button
Protected PageTemplate As MainTemplate

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub


'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()

End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

PageTemplate.LoadChildControls()

ddlEdit = DirectCast(PageTemplate.FindControl("ddlEdit"), DropDownList)
dgDealers = DirectCast(PageTemplate.FindControl("dgDealers"), DataGrid)
cmdApplyChanges = DirectCast(PageTemplate.FindControl("cmdApplychanges"), Button)
cmdGetData = DirectCast(PageTemplate.FindControl("cmdGetData"), Button)

If Not IsPostBack Then
If Not MyBase.IsAdmin Then Response.Redirect("../../../default.aspx")
BindGrid()
End If
End Sub

''Im only putting a couple methods in here all the other events are fine except:

Private Sub dgDealers_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgDealers.ItemCommand

If e.CommandArgument.ToString() = "Retrieve" Then
Dim DealerDB As DealerReportsDB


Dim RetrievePrevious As LinkButton = DirectCast(e.Item.FindControl("lcmdRetrieve"), LinkButton)
'do work .......
End If
End Sub
----------------------------------------------------------------------------------------------

I can't get this event to fire. It seems the nested controls do not even fire the JScript Page_postback correctly. Im sorry for all the code pasting, but I wanted to dictate my situation thouroughly the first time. If I remeber, this is an easy fix, but I would greatly appreciate the advice from someone who has done this more recently than I

Thanks-

Don't bother just to be better than your contemporaries or predecessors. Try to be better than yourself

-William Faulkner
master4eva
Asp.Net User
Re: Need help with Control Events in Page Template Archtitechture7/25/2004 8:12:01 AM

0

Have a look at this post for an example:

http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=641074
-- Justin Lovell
aspkahuna
Asp.Net User
Re: Need help with Control Events in Page Template Archtitechture10/21/2004 7:12:11 PM

0

I figured this out ahwile ago. It has to do with ASP.net and naming containers. If you have your form tag in a user control, then asp messes up the naming converntions of all controls and the default "function __doPostBack(eventTarget, eventArgument) " that asp creates automatically to handle ALL control postbacks will not be called correctly. You will notice this for certain events like MyDataGrid_PageIndexChanged event and MyDataGrid_ItemCommand events. None of these will fire. The way I fixed it was to get an ASP.NET hotfix that addresses that exact problem of fixing the control naming when your form tag is within a user control. The knowledge base article is here - http://support.microsoft.com/?kbid=821156. When you apply the hotfix, everything works great.
Don't bother just to be better than your contemporaries or predecessors. Try to be better than yourself

-William Faulkner
3 Items, 1 Pages 1 |< << Go >> >|


Free Download:


Web:
WebControls HELP!! - ng.asp-net-forum ... Need help with Control Events in Page Template Archtitechture - ng.asp ... Need help with Control Events in Page Template Archtitechture, > ROOT > . ...
Guidance please .NET Membership - ng.asp-net-forum.security - Fix ... need help with control events in page template archtitechture ... NET, it seems that you need to design a separate version of the page for each usertype. ...
WebControls HELP!! - ng.asp-net-forum ... Need help with Control Events in Page Template Archtitechture - ng.asp ... Need help with Control Events in Page Template Archtitechture, > ROOT > . ...
Guidance please .NET Membership - ng.asp-net-forum.security - Fix ... need help with control events in page template archtitechture ... NET, it seems that you need to design a separate version of the page for each usertype. ...
WebControls HELP!! - ng.asp-net-forum ... Need help with Control Events in Page Template Archtitechture - ng.asp ... Need help with Control Events in Page Template Archtitechture, > ROOT > . ...
Guidance please .NET Membership - ng.asp-net-forum.security - Fix ... need help with control events in page template archtitechture ... NET, it seems that you need to design a separate version of the page for each usertype. ...
WebControls HELP!! - ng.asp-net-forum ... Need help with Control Events in Page Template Archtitechture - ng.asp ... Need help with Control Events in Page Template Archtitechture, > ROOT > . ...
Guidance please .NET Membership - ng.asp-net-forum.security - Fix ... need help with control events in page template archtitechture ... NET, it seems that you need to design a separate version of the page for each usertype. ...
WebControls HELP!! - ng.asp-net-forum ... Need help with Control Events in Page Template Archtitechture - ng.asp ... Need help with Control Events in Page Template Archtitechture, > ROOT > . ...
Guidance please .NET Membership - ng.asp-net-forum.security - Fix ... need help with control events in page template archtitechture ... NET, it seems that you need to design a separate version of the page for each usertype. ...












timer

possible to make loginstatus text become underlined when mouse hovers?

why is postback occuring?

request.urlreferrer null

two forms in asp.net page

ms word integration with asp.net

calendar control convert string to date

have to click "search" button twice

browse - update

iframe src assignment

window closing..

question about adding custom content to calendar.

scrolling on datagrid

how to store multiple checked values in sqlserver

multiple validators fire at the same time...

problem using panels

checkboxlist with links: firefox strange behavior

poputate multiple sql fields with one multi value drop down boxe

setting ie's built in progress bar (indicator) in the status bar

refresh frame after or in server side button click of a different frame

wizard control (save and resume at a later time)

exception in binding dependant dropdownlist in a formview (.net 2)

accessing windowscontrols members at the clent side

force file attached and resize image

validation annoyance!

apply validations.

images are not being displayed on my .aspx page?

looking for page name property

creating <asp:textbox runat=server /> dynamically and place in sepecific location

how to specify a network path

 
Search This Site:

 
  Privacy | Contact Us
All Times Are GMT