Hi I have created linkbuttons dynamically using the below code - Sub createlinkbutton(ByVal commandtext As String, ByVal Cmdarg As String, ByVal pane As Panel, ByVal count As Int32)
-
-
Dim i = 0
-
-
Dim panel1 As Panel = New Panel
-
-
panel1.CssClass = "boxx"
-
-
pane.Controls.Add(panel1)
-
-
Dim lbButton As LinkButton = New LinkButton
-
-
lbButton.Text = commandtext
-
-
lbButton.CommandName = commandtext
-
-
lbButton.CommandArgument = Cmdarg
-
-
AddHandler lbButton.Command, AddressOf Me.LinkButton_Command
-
-
panel1.Controls.Add(lbButton)
-
-
End Sub
-
-
-
-
Protected Sub LinkButton_Command(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs)
-
-
If e.CommandArgument.ToString = "Region" Then
-
-
Session("Region") = e.CommandName
-
-
End If
-
-
If e.CommandArgument.ToString = "LEA" Then
-
-
Session("LEA") = e.CommandName
-
-
End If
-
-
If e.CommandArgument.ToString = "Subject" Then
-
-
Session("Subject") = e.CommandName
-
-
End If
-
-
If e.CommandArgument.ToString = "Position" Then
-
-
Session("Position") = e.CommandName
-
-
End If
-
-
If e.CommandArgument.ToString = "SchoolPhase" Then
-
-
Session("SchoolPhase") = e.CommandName
-
-
End If
-
-
Response.Write("<script language=""javascript"">alert(""" & Session("Region") & """)</script>")
-
-
populate()
-
-
End Sub
Linkbuttons are successfully generated. When i click one of the linkbutton. The command event doesn't fired. While I have Add command event handler to the linkbuttons.
What is wrong in my code
Thanks
8 12951 Frinavale 9,735
Recognized Expert Moderator Expert
Where are you calling your "createlinkbutt on" method?
In the Page Init event?
If not then your event will never fire. The link button will post back to the server, but the server will not load the ViewState of the link button, and so the event for the link button will not be loaded...theref ore it will not fire.
-Frinny
@Frinavale
Thanks for your reply.
But The problem is very strange. Please look into code problem once again.
Function to generate linkbuttons. -
Sub createlinkbutton(ByVal commandtext As String, ByVal Cmdarg As String, ByVal pane As Panel, ByVal count As Int32)
-
Dim panela As Panel = New Panel
-
panela.CssClass = "boxx"
-
pane.Controls.Add(panela)
-
Dim lbButton As LinkButton = New LinkButton
-
lbButton.Text = commandtext
-
lbButton.CommandName = commandtext
-
lbButton.CommandArgument = Cmdarg
-
AddHandler lbButton.Command, AddressOf Me.LinkButton_Command
-
AddHandler lbButton.Click, AddressOf Me.LinkButton_Click
-
panela.Controls.Add(lbButton)
-
End Sub
-
And the command event is -
Protected Sub LinkButton_Command(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs)
-
If e.CommandArgument.ToString = "Region" Then
-
Session("Region") = e.CommandName
-
End If
-
If e.CommandArgument.ToString = "LEA" Then
-
Session("LEA") = e.CommandName
-
End If
-
If e.CommandArgument.ToString = "Subject" Then
-
Session("Subject") = e.CommandName
-
End If
-
If e.CommandArgument.ToString = "Position" Then
-
Session("Position") = e.CommandName
-
End If
-
If e.CommandArgument.ToString = "SchoolPhase" Then
-
Session("SchoolPhase") = e.CommandName
-
End If
-
Response.Write("<script language=""javascript"">alert(""" & Session("Region") & """)</script>")
-
populate()
-
Response.Write("<script language='javascript'>alert('hello')</script>")
-
End Sub
-
Another funciton for some other functionality -
Public Sub loadRegion()
-
For k = 0 To DT.Rows.Count
-
createlinkbutton(DT.Rows(k)("Region"), DT.Rows(k)("BtnArg"), Pane1, DT.Rows(k)("num"))
-
Next
-
-
'createlinkbutton("London", "Region", Pane, 12)
-
'createlinkbutton("aLondon", "Region", Pane, 12)
-
'createlinkbutton("Lsondon", "Region", Pane, 12)
-
'createlinkbutton("Lodndon", "Region", Pane, 12)
-
'createlinkbutton("Londdon", "Region", Pane, 12)
-
'createlinkbutton("Londfon", "Region", Pane, 12)
-
'createlinkbutton("Londofn", "Region", Pane, 12)
-
'createlinkbutton("fLondon", "Region", Pane, 12)
-
'createlinkbutton("Lcondon", "Region", Pane, 12)
-
'createlinkbutton("Lovndon", "Region", Pane, 12)
-
'createlinkbutton("Lon don", "Region", Pane, 12)
-
'createlinkbutton("Loncdon", "Region", Pane1, 12)
-
'createlinkbutton("Loncdon", "Region", Pane1, 12)
-
'createlinkbutton("Londxon", "Region", Pane1, 12)
-
'createlinkbutton("Londosn", "Region", Pane1, 12)
-
'createlinkbutton("Londons", "Region", Pane1, 12)
-
'createlinkbutton("kLondon", "Region", Pane1, 12)
-
'createlinkbutton("Ljondon", "Region", Pane, 12)
-
'createlinkbutton("Lonndon", "Region", Pane, 12)
-
'createlinkbutton("Lonndon", "Region", Pane, 12)
-
'createlinkbutton("Londnon", "Region", Pane1, 12)
-
'createlinkbutton("Londonn", "Region", Pane1, 12)
-
End Sub
-
Now if I call the LoadRegion function from any where the button generated don't fires the command event. If i comment the For loop portion and uncomment the
commented portion then the button generated works fine. i.e when i click one of the button command event fires successfully.
Instead of using if i use while loop buttons are created successfully but event doesn't work.
This is very urgent.
Waiting for quick reply.
Frinavale 9,735
Recognized Expert Moderator Expert
Is DT.Rows.Count = 0?
Does your loop actually happen?
Have you tried stepping through this?
You never answered my original question.
Are you calling this in your Page Init event?
@Frinavale
NO DT.Rows.Count is not equals 0 but the loop happen successfully.
And I m calling this from page load event.
Thanks
@Frinavale
Thanks
If from the page load event I call to button create function like below then the command event works fine. -
-
createlinkbutton("Londosn", "Region", Pane1, 12)
-
-
but if i place the same code in for or while loop then the command event doesn't work.
e.g -
for i=1 to 5
-
createlinkbutton("Londosn", "Region", Pane1, 12)
-
Next
-
Here the command event does not work.
Frinavale 9,735
Recognized Expert Moderator Expert
Well,one obvious thing is that you are creating a button with the command name and text "Londosn" in Panel 1, five times. -
for i=1 to 5
-
createlinkbutton("Londosn", "Region", Pane1, 12)
-
Next
-
Have you considered providing unique values (like you do by hand when you aren't looping) to see if it works?
For example: -
for i=1 to 5
-
createlinkbutton("Londosn_"+i.ToString, "Region", Pane1, 12)
-
Next
-
@Frinavale
Thanks for Reply. I have done the job little different. -
<asp:DataList ID="DataList2" runat="server" DataSourceID="SqlDataSource1" RepeatDirection="horizontal"
-
RepeatLayout="Flow">
-
<ItemTemplate>
-
<asp:LinkButton OnCommand="Command" CommandName="Region" CommandArgument='<%# Eval("Region") %>' runat="server"><%# Eval("Region") %></asp:LinkButton>
-
|
-
</ItemTemplate>
-
</asp:DataList>
-
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:dbase_DataConnectionString6 %>"
-
SelectCommand="SELECT [Region] FROM [tblregion]"></asp:SqlDataSource>
-
It is now working fine. thanks.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Linda |
last post by:
Hi,
How do I dynamically add linkbuttons and wire them to same event? I am able to add linkbuttons but they do not fire the event. Does anybody have a working sample?
Many thanks,
Linda
|
by: Grant |
last post by:
The Idea:
Page1.aspx sets a property value to an arraylist.
Page2.aspx retreives that property (using a Context.Handler) every time the
page loads. It then iterates through the arraylist and builds a table
containing dynamically created LinkButtons. These LinkButtons have an event
handler.
The problem:
When I click one of these linkbuttons, the page re-initialises and calls the
Page_Load event. At this point that arraylist is lost and...
|
by: James Norton-Jones |
last post by:
Hi,
I am wanting to create Linkbuttons and Event Handlers on the fly.
Ideally I would be able to pass the CommandName and CommandArgument to the
Event Handler which in turn would pass these to a generic method for
processing.
I have been able to create the LinkButtons themselves on the fly. However I
haven't managed to connect the to an Event Handler.
|
by: Klom Dark |
last post by:
I've got a weird problem going on - I've got a table of dynamically created buttons. Each button has the X/Y value of the buttons position in the table assigned to it's CommandArgument property and the name of a common command (btn_Command) assigned to it's Command property. The creation of the table is done by a function called drawGeo. drawGeo is called during the initial Page_Load (!IsPostBack), but should be called by btn_Command on...
|
by: Solomon Shaffer |
last post by:
This is very interesting - and odd. I have a number of LinkButtons
that are created in a custom data grid that I created. The purpose of
the LinkButtons is to provide alphabetical filtering functionality on
the grid. Therefore, a LinkButton is added for every letter of the
alphabet. I also have a numeric filter button and an "All" button that
removes the filter. All of the LinkButtons are wired up to the same
event called...
| |
by: JoakimR |
last post by:
Hello,
I have a problem with events not firing. I've created a web user
control which renders a calendar using a table control. In two cells
I'm adding LinkButtons for "prev/next month". However, the events from
these are not fired.
In the PageLoad event I check if it's a PostBack. If it isn't, I'm
calling DisplayCalendar() to render the calendar. This part works and I
get the output. If it *is* a postback (i.e. one of the linkbuttons...
|
by: Steve |
last post by:
Hi,
I have a dynamically created ImageButton in a custom control, and I can't
get the control to handle the ImageButton Click event. I see the control in
the Page.Request.Form.AllKeys collection, but it's represented as "imgbtn.X"
(and .Y), and I'm guessing that .NET can't connect the name to the event
since the ID isn't an exact match. I read an article stating that I need to
use IPostBackDataHandler methods, but I didn't have a lot of...
|
by: viovanov |
last post by:
I am trying to get some events to fire properly.
I have a series of LinkButtons with some attribute set, one of which is
unique for each LinkButton. At first I load a few buttons, and I set
their Click event to the same function. In this function I need to add
more LinkButtons. Not a problem at the first click. (I load the
linkButtons once at Load_Page and then I reload them in the click
event). At the second click (on an item created...
|
by: RSH |
last post by:
Hi,
I have a page that is generating Linkbuttons dynamically. I need to
dynamically wire up the buttons to an OnClick handler server side.
I am using this code but they are not firing the event.
What am i missing?
Dim ctrl As New LinkButton
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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.
| |