Can System.EventArgs be cast to CommandEventArgs? If so, how?
Actually I want the Page_Load sub to invoke another sub which is the
OnCommand event handler of a LinkButton.
<script runat="server">
Sub Page_Load(obj As Object, ea As EventArgs)
CallCmd(obj, ??)
End Sub
Sub CallCmd(obj As Object, ea As CommandEventArgs)
..........
..........
End Sub
</script>
<form runat="server">
<asp:LinkButton ID="lnkButton" OnCommand="CallCmd" Text="ABCD"
runat="server"/>
</form>
For the Page_Load sub to invoke CallCmd, the second parameter should be
of type CommandEventArgs. How do I cast EventArgs to CommandEventArgs? 6 4702
Call it like:
CallCmd(obj, CommandEventArgs.Empty)
<rn**@rediffmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
Can System.EventArgs be cast to CommandEventArgs? If so, how?
Actually I want the Page_Load sub to invoke another sub which is the
OnCommand event handler of a LinkButton.
<script runat="server">
Sub Page_Load(obj As Object, ea As EventArgs)
CallCmd(obj, ??)
End Sub
Sub CallCmd(obj As Object, ea As CommandEventArgs)
..........
..........
End Sub
</script>
<form runat="server">
<asp:LinkButton ID="lnkButton" OnCommand="CallCmd" Text="ABCD"
runat="server"/>
</form>
For the Page_Load sub to invoke CallCmd, the second parameter should be
of type CommandEventArgs. How do I cast EventArgs to CommandEventArgs?
Joseph, I am getting the following error:
Unable to cast object of type 'System.EventArgs' to type
'System.Web.UI.WebControls.CommandEventArgs'.
pointing to the line
CallCmd(obj, CommandEventArgs.Empty)
Any other suggestions?
JosephByrns wrote:
Call it like:
CallCmd(obj, CommandEventArgs.Empty)
<rn**@rediffmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
Can System.EventArgs be cast to CommandEventArgs? If so, how?
Actually I want the Page_Load sub to invoke another sub which is the
OnCommand event handler of a LinkButton.
<script runat="server">
Sub Page_Load(obj As Object, ea As EventArgs)
CallCmd(obj, ??)
End Sub
Sub CallCmd(obj As Object, ea As CommandEventArgs)
..........
..........
End Sub
</script>
<form runat="server">
<asp:LinkButton ID="lnkButton" OnCommand="CallCmd" Text="ABCD"
runat="server"/>
</form>
For the Page_Load sub to invoke CallCmd, the second parameter should be
of type CommandEventArgs. How do I cast EventArgs to CommandEventArgs?
Hmmm, I tried it got the same error, I have no idea why that happens, but if
you try:
CallCmd(obj, Nothing)
instead, then it will work.
<rn**@rediffmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
Joseph, I am getting the following error:
Unable to cast object of type 'System.EventArgs' to type
'System.Web.UI.WebControls.CommandEventArgs'.
pointing to the line
CallCmd(obj, CommandEventArgs.Empty)
Any other suggestions?
JosephByrns wrote:
>Call it like:
CallCmd(obj, CommandEventArgs.Empty)
<rn**@rediffmail.comwrote in message news:11**********************@k70g2000cwa.googleg roups.com...
Can System.EventArgs be cast to CommandEventArgs? If so, how?
Actually I want the Page_Load sub to invoke another sub which is the
OnCommand event handler of a LinkButton.
<script runat="server">
Sub Page_Load(obj As Object, ea As EventArgs)
CallCmd(obj, ??)
End Sub
Sub CallCmd(obj As Object, ea As CommandEventArgs)
..........
..........
End Sub
</script>
<form runat="server">
<asp:LinkButton ID="lnkButton" OnCommand="CallCmd" Text="ABCD"
runat="server"/>
</form>
For the Page_Load sub to invoke CallCmd, the second parameter should be
of type CommandEventArgs. How do I cast EventArgs to CommandEventArgs?
Yeah Joseph that works but the problem is I am using the
CommandArgument property of the LinkButton (sorry, I should have
mentioned this before)
<asp:LinkButton ID="lnkButton" OnCommand="CallCmd"
CommandArgument="Col1" Text="ABCD" runat="server"/>
The CallCmd sub looks like this:
Sub CallCmd(obj As Object, ea As CommandEventArgs)
txtCall.Text = ea.CommandArgument
..........
..........
End Sub
Now when I invoke CallCmd from Page_Load using
CallCmd(obj, Nothing)
then ASP.NET generates the following error:
Object reference not set to an instance of an object.
pointing to the first line shown above in the sub CallCmd!
Any other ideas??
JosephByrns wrote:
Hmmm, I tried it got the same error, I have no idea why that happens, but if
you try:
CallCmd(obj, Nothing)
instead, then it will work.
<rn**@rediffmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
Joseph, I am getting the following error:
Unable to cast object of type 'System.EventArgs' to type
'System.Web.UI.WebControls.CommandEventArgs'.
pointing to the line
CallCmd(obj, CommandEventArgs.Empty)
Any other suggestions?
JosephByrns wrote:
Call it like:
CallCmd(obj, CommandEventArgs.Empty)
<rn**@rediffmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
Can System.EventArgs be cast to CommandEventArgs? If so, how?
Actually I want the Page_Load sub to invoke another sub which is the
OnCommand event handler of a LinkButton.
<script runat="server">
Sub Page_Load(obj As Object, ea As EventArgs)
CallCmd(obj, ??)
End Sub
Sub CallCmd(obj As Object, ea As CommandEventArgs)
..........
..........
End Sub
</script>
<form runat="server">
<asp:LinkButton ID="lnkButton" OnCommand="CallCmd" Text="ABCD"
runat="server"/>
</form>
For the Page_Load sub to invoke CallCmd, the second parameter should be
of type CommandEventArgs. How do I cast EventArgs to CommandEventArgs?
You could either check to see if it is nothing before you use ea or you
could call it like:
CallCmd(Me, New CommandEventArgs("Command From Load", "LoadArgument1"))
<rn**@rediffmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
Yeah Joseph that works but the problem is I am using the
CommandArgument property of the LinkButton (sorry, I should have
mentioned this before)
<asp:LinkButton ID="lnkButton" OnCommand="CallCmd"
CommandArgument="Col1" Text="ABCD" runat="server"/>
The CallCmd sub looks like this:
Sub CallCmd(obj As Object, ea As CommandEventArgs)
txtCall.Text = ea.CommandArgument
..........
..........
End Sub
Now when I invoke CallCmd from Page_Load using
CallCmd(obj, Nothing)
then ASP.NET generates the following error:
Object reference not set to an instance of an object.
pointing to the first line shown above in the sub CallCmd!
Any other ideas??
JosephByrns wrote:
>Hmmm, I tried it got the same error, I have no idea why that happens, but if you try:
CallCmd(obj, Nothing)
instead, then it will work.
<rn**@rediffmail.comwrote in message news:11**********************@e3g2000cwe.googlegr oups.com...
Joseph, I am getting the following error:
Unable to cast object of type 'System.EventArgs' to type
'System.Web.UI.WebControls.CommandEventArgs'.
pointing to the line
CallCmd(obj, CommandEventArgs.Empty)
Any other suggestions?
JosephByrns wrote: Call it like:
CallCmd(obj, CommandEventArgs.Empty)
<rn**@rediffmail.comwrote in message news:11**********************@k70g2000cwa.googleg roups.com...
Can System.EventArgs be cast to CommandEventArgs? If so, how?
Actually I want the Page_Load sub to invoke another sub which is the
OnCommand event handler of a LinkButton.
<script runat="server">
Sub Page_Load(obj As Object, ea As EventArgs)
CallCmd(obj, ??)
End Sub
Sub CallCmd(obj As Object, ea As CommandEventArgs)
..........
..........
End Sub
</script>
<form runat="server">
<asp:LinkButton ID="lnkButton" OnCommand="CallCmd" Text="ABCD"
runat="server"/>
</form>
For the Page_Load sub to invoke CallCmd, the second parameter should
be
of type CommandEventArgs. How do I cast EventArgs to
CommandEventArgs?
Better yet, refactor your event handler to pass its work on to another
method
Sub CallCmd(sender as Object, e as CommandEventArgs)
DoSomethingWithCmd(e.CommandArgument)
End Sub
Sub DoSomethingWithCmd(argument as string)
...
End Sub
Sub Page_Load(sender as object, e as EventArgs)
...
DoSomethingWithCmd(somePredefinedString)
...
End Sub
Generally, you'll find your life easier if Event Handlers do _nothing_
but handle an event. The actual work should be done in a different
method for precisely this reason.
Joseph Byrns wrote:
You could either check to see if it is nothing before you use ea or you
could call it like:
CallCmd(Me, New CommandEventArgs("Command From Load", "LoadArgument1"))
<rn**@rediffmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
Yeah Joseph that works but the problem is I am using the
CommandArgument property of the LinkButton (sorry, I should have
mentioned this before)
<asp:LinkButton ID="lnkButton" OnCommand="CallCmd"
CommandArgument="Col1" Text="ABCD" runat="server"/>
The CallCmd sub looks like this:
Sub CallCmd(obj As Object, ea As CommandEventArgs)
txtCall.Text = ea.CommandArgument
..........
..........
End Sub
Now when I invoke CallCmd from Page_Load using
CallCmd(obj, Nothing)
then ASP.NET generates the following error:
Object reference not set to an instance of an object.
pointing to the first line shown above in the sub CallCmd!
Any other ideas??
JosephByrns wrote:
Hmmm, I tried it got the same error, I have no idea why that happens, but
if
you try:
CallCmd(obj, Nothing)
instead, then it will work.
<rn**@rediffmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
Joseph, I am getting the following error:
Unable to cast object of type 'System.EventArgs' to type
'System.Web.UI.WebControls.CommandEventArgs'.
pointing to the line
CallCmd(obj, CommandEventArgs.Empty)
Any other suggestions?
JosephByrns wrote:
Call it like:
CallCmd(obj, CommandEventArgs.Empty)
<rn**@rediffmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
Can System.EventArgs be cast to CommandEventArgs? If so, how?
Actually I want the Page_Load sub to invoke another sub which is the
OnCommand event handler of a LinkButton.
<script runat="server">
Sub Page_Load(obj As Object, ea As EventArgs)
CallCmd(obj, ??)
End Sub
Sub CallCmd(obj As Object, ea As CommandEventArgs)
..........
..........
End Sub
</script>
<form runat="server">
<asp:LinkButton ID="lnkButton" OnCommand="CallCmd" Text="ABCD"
runat="server"/>
</form>
For the Page_Load sub to invoke CallCmd, the second parameter should
be
of type CommandEventArgs. How do I cast EventArgs to
CommandEventArgs? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jacob Jensen |
last post by:
This question has probably been asked a million time, but here it comes
again. I want to learn the difference between the three type cast operators:
static_cast, reinterpret_cast, dynamic_cast. A...
|
by: Brian Blais |
last post by:
Hello,
I saw on a couple of recent posts people saying that casting the return
value of malloc is bad, like:
d=(double *) malloc(50*sizeof(double));
why is this bad? I had always thought...
|
by: ytrama |
last post by:
Hi,
I have read in one of old posting that don't cast of pointer which
is returned by the malloc. I would like to know the reason.
Thanks in advance,
YTR
|
by: yufufi |
last post by:
lets say we have a 'shape' class which doesn't implement IComparable
interface..
compiler doesn't give you error for the lines below..
shape b= new shape();
IComparable h;
h=(IComparable)b;...
|
by: Jim Bancroft |
last post by:
Hi everyone,
A basic one here, I think. I haven't found the pattern yet, but
sometimes when I cast a variable to another type using the "C" style cast
operator the compiler refuses to play...
|
by: Enrique Bustamante |
last post by:
Casting arrays that works on watch and command window but not in code.
My application is casting arrays in a way it should work. To test if I
was doing something invalid, I wrote a test code that...
|
by: S. Lorétan |
last post by:
Hi guys,
Sorry for this stupid question, but I don't know why it isn't working.
Here is my (example) code:
namespace Test {
class A {
public string Label1;
}
|
by: sophia.agnes |
last post by:
Hi ,
I was going through peter van der linden's book Expert C programming,
in this book there is a section named "How and why to cast"
the author then says as follows
(float) 3 - it's a...
|
by: Taras_96 |
last post by:
Hi everyone,
I was experimenting with static_cast and reinterpret cast
#include <iostream>
struct A1 { int a; };
struct A2 { double d; };
struct B : public A1, A2
|
by: Tinkertim |
last post by:
Hi,
I have often wondered if casting the return value of malloc() (or
friends) actually helps anything, recent threads here suggest that it
does not .. so I hope to find out.
For instance :
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |