Well I'm trying to catch and act upon a button event that is placed within
the item template of a repeater control. Yet the code I'm using isn't
working. What I've seen out there to explain how to do this is way
complicated and assumes a familiarity with dot net that I don't have yet.
I'll get it eventually but this is where I'll get it. Here's my code.
First part is the user control and second is the code behind page
Use control
<%@ Control Language="vb" AutoEventWireup ="false"
Codebehind="Sit eList.ascx.vb" Inherits="GSICo mputerServices. SiteList"
TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5" %>
<asp:Repeater id="SiteRepeate r" runat="server"
OnItemCommand=" SiteRepeater_It emCommand">
<ItemTemplate >
<tr>
<td>
<asp:Button Text='<%#
CType(Databinde r.Eval(Containe r.DataItem,"Sit eName"),String) .Trim %>'
Runat="server" Font-Bold=True CommandArgument ='<%#
CType(Databinde r.Eval(Containe r.DataItem,"Sit eID"),String).T rim()%>'
CommandName='Si teIDButton' Width="100px">
</asp:Button>
</td>
</tr>
</ItemTemplate>
<HeaderTemplate >
<table border="0" cellpadding="0" cellspacing="0" >
</HeaderTemplate>
<FooterTemplate >
</table>
</FooterTemplate>
<SeparatorTempl ate>
</SeparatorTempla te>
</asp:Repeater>
code behind
Imports System.Data.Sql Client
Imports System.Data
Imports GSIComputerServ ices
Public Class SiteList
Inherits System.Web.UI.U serControl
Dim useparent As Master
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()
End Sub
Protected WithEvents SiteRepeater As System.Web.UI.W ebControls.Repe ater
Protected WithEvents LinkButton1 As System.Web.UI.W ebControls.Link Button
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim sql As String
Dim db As SqlConnection
Dim comm As SqlCommand
Dim dread As SqlDataReader
sql = "Select * From _Site where MasterID = " &
CType(Session.C ontents("Master ID"), Integer) & ""
db = New SqlConnection(" ")
db.Open()
comm = New SqlCommand(sql, db)
dread = comm.ExecuteRea der
Me.SiteRepeater .DataSource = dread
Me.SiteRepeater .DataBind()
db.Close()
'Put user code to initialize the page here
End Sub
Public Sub ChooseSite(ByVa l siteID As String)
Me.useparent.Ch ooseSite(siteID )
End Sub
Public Property componentParent () As Master
Get
Return Me.useparent
End Get
Set(ByVal Value As Master)
Me.useparent = Value
End Set
End Property
Public Sub SiteRepeater_It emCommand(ByVal source As Object, ByVal e As
System.Web.UI.W ebControls.Repe aterCommandEven tArgs) Handles
SiteRepeater.It emCommand
'ChooseSite("al l")
ChooseSite(CTyp e(e.CommandArgu ment(), String))
End Sub
End Class 2 3186
Hi,
you seem to be databinding the grid on every request and that's why
ItemCommand event wouldn't be raised on postback (because it is cleared on
rebinding when rebinding happens "too early").
Put the code that bind the grid in Page_Load inside:
If Not Page.IsPostBack Then
'code to bind here
End If
and ItemCommand event starts to raise.
--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
"Jorge Ayala" <jo***@gsicompu terservices.com > wrote in message
news:uO******** ******@tk2msftn gp13.phx.gbl... Well I'm trying to catch and act upon a button event that is placed within the item template of a repeater control. Yet the code I'm using isn't working. What I've seen out there to explain how to do this is way complicated and assumes a familiarity with dot net that I don't have yet. I'll get it eventually but this is where I'll get it. Here's my code. First part is the user control and second is the code behind page
Use control
<%@ Control Language="vb" AutoEventWireup ="false" Codebehind="Sit eList.ascx.vb" Inherits="GSICo mputerServices. SiteList" TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5" %> <asp:Repeater id="SiteRepeate r" runat="server" OnItemCommand=" SiteRepeater_It emCommand"> <ItemTemplate > <tr> <td> <asp:Button Text='<%# CType(Databinde r.Eval(Containe r.DataItem,"Sit eName"),String) .Trim %>' Runat="server" Font-Bold=True CommandArgument ='<%# CType(Databinde r.Eval(Containe r.DataItem,"Sit eID"),String).T rim()%>' CommandName='Si teIDButton' Width="100px"> </asp:Button> </td> </tr> </ItemTemplate> <HeaderTemplate > <table border="0" cellpadding="0" cellspacing="0" > </HeaderTemplate> <FooterTemplate > </table> </FooterTemplate> <SeparatorTempl ate> </SeparatorTempla te> </asp:Repeater>
code behind Imports System.Data.Sql Client
Imports System.Data
Imports GSIComputerServ ices
Public Class SiteList
Inherits System.Web.UI.U serControl
Dim useparent As Master
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent() End Sub
Protected WithEvents SiteRepeater As System.Web.UI.W ebControls.Repe ater
Protected WithEvents LinkButton1 As System.Web.UI.W ebControls.Link Button
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub
#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
Dim sql As String
Dim db As SqlConnection
Dim comm As SqlCommand
Dim dread As SqlDataReader
sql = "Select * From _Site where MasterID = " & CType(Session.C ontents("Master ID"), Integer) & ""
db = New SqlConnection(" ")
db.Open()
comm = New SqlCommand(sql, db)
dread = comm.ExecuteRea der
Me.SiteRepeater .DataSource = dread
Me.SiteRepeater .DataBind()
db.Close()
'Put user code to initialize the page here
End Sub
Public Sub ChooseSite(ByVa l siteID As String)
Me.useparent.Ch ooseSite(siteID )
End Sub
Public Property componentParent () As Master
Get
Return Me.useparent
End Get
Set(ByVal Value As Master)
Me.useparent = Value
End Set
End Property
Public Sub SiteRepeater_It emCommand(ByVal source As Object, ByVal e As System.Web.UI.W ebControls.Repe aterCommandEven tArgs) Handles SiteRepeater.It emCommand
'ChooseSite("al l")
ChooseSite(CTyp e(e.CommandArgu ment(), String))
End Sub
End Class
Actually I databind() repeaters on each Page_Load, I never
check for IsPostBack and it works just fine... Infact if
you have an OnItemDataBound event that dynamically adds
buttons into your Repeater Items you HAVE TO databind() on
each Page_Load or the dynamically created button will
disappear at post back, so you have to recreate it at each
page load so the ItemCommand triggers...
the problem here which i noticed also is actually a bug.
Button ItemCommand events are NOT bubbled to their parent
Repeater. LinkButtons are. It is quite frustrating because
in help it clearly states Buttons are supposed to work
this way and they don't, they never fire the ItemCommand
event.. LinkButtons do... Maybe it has something to do
with Buttons generating input type=submit and LinkButtons
generate javascript :do_s ubmit or something like that..
anyway, something is definitely wrong here... try it out.. -----Original Message----- Hi,
you seem to be databinding the grid on every request and
that's whyItemCommand event wouldn't be raised on postback (because
it is cleared onrebinding when rebinding happens "too early").
Put the code that bind the grid in Page_Load inside:
If Not Page.IsPostBack Then 'code to bind here End If
and ItemCommand event starts to raise.
-- Teemu Keiski MCP, Microsoft MVP (ASP.NET), AspInsiders member ASP.NET Forum Moderator, AspAlliance Columnist
"Jorge Ayala" <jo***@gsicompu terservices.com > wrote in
messagenews:uO******* *******@tk2msft ngp13.phx.gbl.. . Well I'm trying to catch and act upon a button event
that is placed within the item template of a repeater control. Yet the code
I'm using isn't working. What I've seen out there to explain how to do
this is way complicated and assumes a familiarity with dot net
that I don't have yet. I'll get it eventually but this is where I'll get it.
Here's my code. First part is the user control and second is the code
behind page
Use control
<%@ Control Language="vb" AutoEventWireup ="false" Codebehind="Sit eList.ascx.vb"
Inherits="GSICo mputerServices. SiteList"
TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5
" %> <asp:Repeater id="SiteRepeate r" runat="server" OnItemCommand=" SiteRepeater_It emCommand"> <ItemTemplate > <tr> <td> <asp:Button Text='<%# CType(Databinde r.Eval
(Container.Data Item,"SiteName" ),String).Trim %>' Runat="server" Font-Bold=True CommandArgument ='<%# CType(Databinde r.Eval
(Container.Data Item,"SiteID"), String).Trim()% >' CommandName='Si teIDButton' Width="100px"> </asp:Button> </td> </tr> </ItemTemplate> <HeaderTemplate > <table border="0" cellpadding="0" cellspacing="0" > </HeaderTemplate> <FooterTemplate > </table> </FooterTemplate> <SeparatorTempl ate> </SeparatorTempla te> </asp:Repeater>
code behind Imports System.Data.Sql Client
Imports System.Data
Imports GSIComputerServ ices
Public Class SiteList
Inherits System.Web.UI.U serControl
Dim useparent As Master
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeComp onent() End Sub
Protected WithEvents SiteRepeater As
System.Web.UI.W ebControls.Repe ater Protected WithEvents LinkButton1 As
System.Web.UI.W ebControls.Link Button 'NOTE: The following placeholder declaration is
required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer 'Do not modify it using the code editor.
InitializeCompo nent()
End Sub
#End Region Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles MyBase.Load
Dim sql As String
Dim db As SqlConnection
Dim comm As SqlCommand
Dim dread As SqlDataReader
sql = "Select * From _Site where MasterID = " & CType(Session.C ontents("Master ID"), Integer) & ""
db = New SqlConnection(" ")
db.Open()
comm = New SqlCommand(sql, db)
dread = comm.ExecuteRea der
Me.SiteRepeater .DataSource = dread
Me.SiteRepeater .DataBind()
db.Close()
'Put user code to initialize the page here
End Sub
Public Sub ChooseSite(ByVa l siteID As String)
Me.useparent.Ch ooseSite(siteID )
End Sub
Public Property componentParent () As Master
Get
Return Me.useparent
End Get
Set(ByVal Value As Master)
Me.useparent = Value
End Set
End Property
Public Sub SiteRepeater_It emCommand(ByVal source As
Object, ByVal e As System.Web.UI.W ebControls.Repe aterCommandEven tArgs)
Handles SiteRepeater.It emCommand
'ChooseSite("al l")
ChooseSite(CTyp e(e.CommandArgu ment(), String))
End Sub
End Class
. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stan |
last post by:
I cannot make the link buttons fire ItemCommand from
repeater control.
Here is the code:
<asp:repeater id=rptLetters runat="server">
<itemtemplate>
<asp:linkbutton id="lnkLetter"
runat="server" commandname="Filter"
CommandArgument='<%#
|
by: luca |
last post by:
I'm trying to build a Server Control, it's a calendar to manage sellers
appointments (don't answer me to use and custumize Calendar Control because
unluckily it's not possible for this specific project).
A piece of my control's interface is composed of a table and in each of its
cells are stored informations about a seller, a date and a time range.
Each of these cells has to be an interactive element: I should be able to
process datas...
|
by: JezB |
last post by:
I am dynamically creating WebControls and creating them on my page. Some of
these are buttons, and I attach events to these buttons. The problem is
these force a post-back, so I must regenerate all the webcontrols in the
same way (I am assuming - am I right?).
It was all working fine but now I get the error:
"An error has occurred because a control with auto-generated id '_ctl129'
could not be located to raise a postback event. To...
|
by: mike |
last post by:
How do i perform a databind on a web user control within a repeater or rather
how can I access the datasource that is already bound? I have a web user
control that displays a table of values (the profile of a piece of equipment)
from SQLServer. I've used a repeater on the webform since a query (i.e. by
address) against the DB may return multiple machine profiles and I want to
use the repeater to display as many machine profiles as are...
|
by: Wayne Sepega |
last post by:
I have the following Code:
foreach (MyClass d in myClassCollection)
{
curRadioBtn = new RadioButton();
curRadioBtn.Text = d.ToString();
curRadioBtn.GroupName = "Contact";
curRadioBtn.ID = d.Name;
curRadioBtn.EnableViewState = true;
curRadioBtn.CheckedChanged += RadioButton_CheckedChanged;
| |
by: Jaybuffet |
last post by:
my aspx has something like this
<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<mycontrol:ctl id="ctlId" obj='<%# Container.DataItem %>'
showItem="true"/>
</ItemTemplate>
/asp:Repeater>
The DataSource for this Repeater is a CollectionBase of objects and is
|
by: Totto |
last post by:
Hi,
Anyone know the best solution to dynamically add buttons to a asp 2.0 page
using data from Sql server?
Are there any contols suitable for this or is it best to iterate the dataset
and dynamicaly add buttons in the asp page?
Totto
|
by: Mark |
last post by:
Assume you want to dynamically add one to many link button controls to a web
page dynamically at run time. Each link button needs to post back and
execute code. As the link buttons are created at run time and the number may
vary, we can't statically tie to the event to a control. I'm assuming I
need to dynamically add event handlers at run time, and that one method
could act as the event handler, with unique event args being created for...
|
by: =?Utf-8?B?Um9nZXIweDE=?= |
last post by:
Language: c#,.net 2
This looks simple in concept: I have a page that needs to display a userid,
a date/time to start vacation, a date/time to end the vacation, and two
buttons: one says approve, the other deny. When you press Approve, it
updates the sql table from pending to approved, when you press deny, it
updates the sql table from pending to denied.
The simplest solution looks to be a repeater which will display the three
data...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |