i created a new button object. how do i attach an event
on it? thanx for your help.
Dim cc As ColorConverter = new ColorConverter( )
Dim b = new button()
b.ID = "SelectedDa te"
b.BorderStyle = 1
b.forecolor = cc.ConvertFromS tring("red")
b.BackColor = cc.ConvertFromS tring("white")
b.BorderColor = cc.ConvertFromS tring("white")
b.text = "hello"
b.click = Test
Sub Test
...do something
End Sub 3 4060
Hi,
Declare the instance as follows
Friend WitEvents b as Button
Then when you create the button, remeber to add it to the Controls
collection of the form
b = New Button
b.Text = "Hello"
b.Location = new Point(0,0)
Controls.Add( b )
Then the event handler should be declared as follows
Sub Test( ByVal sender As Object, ByVal e as EventArgs) Handles b.Click
MsgBox("Hey you clicked me!")
End Sub
Hope this helps
Chris Taylor
"Aymer" <ay****@yahoo.c om> wrote in message
news:03******** *************** *****@phx.gbl.. . i created a new button object. how do i attach an event on it? thanx for your help.
Dim cc As ColorConverter = new ColorConverter( ) Dim b = new button() b.ID = "SelectedDa te"
b.BorderStyle = 1 b.forecolor = cc.ConvertFromS tring("red") b.BackColor = cc.ConvertFromS tring("white") b.BorderColor = cc.ConvertFromS tring("white") b.text = "hello" b.click = Test
Sub Test ...do something End Sub
thanx for the replay. but i still have a problem. there
is nothing wrong with ur code. i tried and tested ur code
and it works fine. however, i am creating the button
inside the content of an asp:calendar. look at the code
below:
<%@ Page Language="vb" Debug="true" %>
<%@ Import Namespace="Syst em" %>
<%@ Import Namespace="Syst em.Web" %>
<%@ Import Namespace="Syst em.Web.UI.WebCo ntrols" %>
<html>
<head>
<script language="vb" runat="server">
Sub Page_Load(sende r As Object, e As EventArgs)
pnlUserInfo.Vis ible = False
pnlCalendar.Vis ible = True
End Sub
Sub Calendar1_DayRe nder(sender As Object, e As
DayRenderEventA rgs)
Dim d As CalendarDay
Dim c As TableCell
d = e.Day
c = e.Cell
If d.IsOtherMonth Then
c.Controls.Clea r
Else
Try
If e.Day.Date = "8/25/2003" Then
Dim b As New Button
b.text = "hello"
AddHandler b.Click, AddressOf Text
e.Cell.Controls .Add(b)
e.Cell.Controls .Add(New LiteralControl( "hello"))
End If
Catch exc As Exception
Response.Write( exc.ToString())
End Try
End If
End Sub
Sub Date_Selected(s ender As Object, e As EventArgs)
pnlCalendar.Vis ible = False
pnlUserInfo.Vis ible = True
End Sub
Sub Text(sender As Object, e As EventArgs)
If txt1.text = "" Or txt1.text = "mornin" Then
txt1.text = "hello to you too."
Else
txt1.text = "mornin"
End If
End Sub
</script>
</head>
<body>
<form id="Form1" runat="server">
<asp:panel id="pnlCalendar " runat="server">
<asp:textbox id="txt1" runat="server" />
<asp:calendar id="calendar1" runat="server"
cellpadding="0"
width="600px"
daystyle-height="65px"
borderwidth="1p x"
onselectionchan ged="Date_Selec ted"
ondayrender="Ca lendar1_DayRend er"
showgridlines=" true"
/>
</asp:calendar>
</asp:panel>
<asp:panel id="pnlUserInfo " runat="server">
<asp:label runat="server" id="label1" text="Blah Blah" />
<asp:button id="btn1" runat="server" text="calendar"
onclick="Calend ar"/>
</asp:panel>
</form>
</body>
</html>
if i add the new button into the form, the attach event
works. but if i add the new button inside the calendar,
the attach event does not work. please help if u can.
Hi,
Ok, first let me say that I do very little ASP.NET, mostly WinForms. So this
might not be the best solution. But after some investigation into your
problem this is what I have concluded.
When adding the controls dynamically the events must be wired in the
Page_Load since the events are fired then. If it is only done when your Cell
is rendered, the ASP.NET event firing has already been done so it is to
late. Additionally the control must belong to a control collection before
the events are fired. With this in mind, my solution entailed placing a
PlaceHolder on the page. Then in the Page_Load event I created the button,
added it to the PlaceHolder controls collection and wired the event. After
this the events Fire. Then in the Page_PreRender event I clear the
PlaceHolder controls collection, this prevents the control actually showing
in the PlaceHolder. In the DayRender I added the Button to the Cells control
collection causing the Button to appear in the correct place. I hope this
helps and I really hope there is a better solution!
See Code Below
NB: I changed the date format to work on my locale, so you will have to
change that!!!
Regards
Chris Taylor
<%@ Page Language="vb" Debug="true" %>
<%@ Import Namespace="Syst em" %>
<%@ Import Namespace="Syst em.Web" %>
<%@ Import Namespace="Syst em.Web.UI.WebCo ntrols" %>
<HTML>
<HEAD>
<script language="vb" runat="server">
Friend WithEvents b as Button
Sub Page_Load(sende r As Object, e As EventArgs)
pnlUserInfo.Vis ible = False
pnlCalendar.Vis ible = True
AddHandler button1.Click, AddressOf b_click
b = new Button()
b.text = "hello"
b.ID = "b"
PlaceHolder1.co ntrols.Add(b)
AddHandler b.Click, AddressOf b_click
End Sub
sub Page_PreRender( sender As Object, e As EventArgs)
placeholder1.co ntrols.clear()
end sub
Sub Calendar1_DayRe nder(sender As Object, e As DayRenderEventA rgs)
Dim d As CalendarDay
Dim c As TableCell
d = e.Day
c = e.Cell
If d.IsOtherMonth Then
c.Controls.Clea r
Else
Try
If e.Day.Date = DateTime.Parse( "25/8/2003") Then
e.Cell.Controls .Add(b)
End If
Catch exc As Exception
Response.Write( exc.ToString())
End Try
End If
End Sub
Sub Date_Selected(s ender As Object, e As EventArgs)
pnlCalendar.Vis ible = False
pnlUserInfo.Vis ible = True
End Sub
Sub b_click(sender As Object, e As EventArgs)
If txt1.text = "" Or txt1.text = "mornin" Then
txt1.text = "hello to you too."
Else
txt1.text = "mornin"
End If
End Sub
</script>
</HEAD>
<body>
<form id="Form1" runat="server">
<asp:panel id="pnlCalendar " runat="server">
<asp:textbox id="txt1" runat="server"> </asp:textbox>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
<asp:PlaceHolde r id="PlaceHolder 1" runat="server"> </asp:PlaceHolder >
<asp:calendar id="calendar1" runat="server" cellpadding="0"
width="600px" daystyle-height="65px"
borderwidth="1p x" onselectionchan ged="Date_Selec ted"
ondayrender="Ca lendar1_DayRend er" showgridlines=" true"></asp:calendar>
</asp:panel><asp: panel id="pnlUserInfo " runat="server">
<asp:label id="label1" runat="server" text="Blah Blah"></asp:label>
</asp:panel></form>
</body>
</HTML> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: tony kulik |
last post by:
This code works fine in ie and opera but not at all in Mozilla.
Anybody got a clue as to how to get it right?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<script language="JavaScript" type="text/javascript">
function show(that)
{
if (box.style.visibility=='hidden') { that.style.visibility =
'visible'};
}
|
by: bhatiaajay |
last post by:
I am new to JavaScript objects. The object creates a button with no
events attached. Later I want to attach an event to the button created
by this object. The event attaches a function in the object.
The code is listed below but the event is never attached.
The 'this' reference for the button seem to be correct and the
'self'
reference...
|
by: Big D |
last post by:
I have a class that inherits from System.Web.Ui.Usercontrol... all is
basically is is a button which is created progammatically such as:
public abstract class BaseFrontEndEditor : System.Web.UI.UserControl
{
protected Button btnEdit = new Button();
private void Page_Load(object sender, System.EventArgs e)
{
|
by: Ashish |
last post by:
Hello,
I am sick and tired of ochestrating server and client side scripts.
Basically I am using toolbar from IE web controls and want to attach
javascript to one of the buttons' click event. The problem is that button
doesnt exposes attribute collection. I can attach javascript to whole
toolbar but 1. it would defeat the purpose of only...
|
by: Nirmalkumar |
last post by:
How to attach an event to dynamically created control in VB.NET
I have dynamically created dropdown list in code behind (VB.NET). For this
control I want to attach an event for action ‘OnSelectedIndexChanged’.
What is the property to assigne an event to a dynamically created dropdownlist
| |
by: Aymer |
last post by:
i created a new button object. how do i attach an event
on it? thanx for your help.
Dim cc As ColorConverter = new ColorConverter()
Dim b = new button()
b.ID = "SelectedDate"
b.BorderStyle = 1
b.forecolor = cc.ConvertFromString("red")
b.BackColor = cc.ConvertFromString("white")
|
by: Ken Sturgeon |
last post by:
I have a button inside a panel control. Apparently I can't expect VB to
respond to the button's _Click event. How do I capture the click event?
Thanks
Ken
|
by: calebmichaud |
last post by:
Hi
I am having trouble understanding how to attach a file or files to a
record. I want to (in form view0 allow the user to attach one or more
than one file to the associated record, and then from then have the
link displayed on the form. All the files would be displayed on the
computers harddrive (or a network folder) and not in the db...
|
by: sindhu |
last post by:
Hello,
I am able to attach event to dynamically created element.as shown below.
for(var i=0;i<10;i++)
{for(var j=0;j<15;j++)
{
var div=document.createElement('div');
div.setAttribute("name","div"+i+j);
div.setAttribute("id","div"+i+j);
|
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...
|
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. ...
| |
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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...
|
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...
|
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...
| |