Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Can I get the ID or CommandName of a Server Control from my code behind code?

Reply
Thread Tools

Can I get the ID or CommandName of a Server Control from my code behind code?

 
 
Mike
Guest
Posts: n/a
 
      01-23-2004
Hi,

I have question that I think should I know the answer to but don't.

In my ASP.NET file, default.aspx I have the following code.

<asp:Button id="Mday1" OnClick="Mday_Click" Text="+" Runat="server"
CommandName="Mday1"></asp:Button>
<asp:Button id="Mday2" OnClick="Mday_Click" Text="+" Runat="server"
CommandName="Mday2"></asp:Button>

in my code behind file, default.aspx.cs I have the following function

protected void Mday_Click(object sender, System.EventArgs e)
{
string debug = null, cname=null;

debug = "You clicked control" + cname;
}

When I click either button on the web page it finds the event, (By
setting a breakpoint I know it has). What I want to know is which of
the buttons it came from. Is this possible or am I asking the wrong
question?

When I am debugging (in Visual Studio) by looking 'into' the sender ->
System.Web.UI.WebControls.Button -> CommandName I can see what the
command name is. How do I get this CommandName?

Any help greatly appreciated.
Mike
 
Reply With Quote
 
 
 
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      01-23-2004
hi mike,
protected void Mday_Click(object sender, System.EventArgs e)
{
this.Response.Write("You clicked the " + e.CommandName + " button.");
}
"Mike" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hi,
>
> I have question that I think should I know the answer to but don't.
>
> In my ASP.NET file, default.aspx I have the following code.
>
> <asp:Button id="Mday1" OnClick="Mday_Click" Text="+" Runat="server"
> CommandName="Mday1"></asp:Button>
> <asp:Button id="Mday2" OnClick="Mday_Click" Text="+" Runat="server"
> CommandName="Mday2"></asp:Button>
>
> in my code behind file, default.aspx.cs I have the following function
>
> protected void Mday_Click(object sender, System.EventArgs e)
> {
> string debug = null, cname=null;
>
> debug = "You clicked control" + cname;
> }
>
> When I click either button on the web page it finds the event, (By
> setting a breakpoint I know it has). What I want to know is which of
> the buttons it came from. Is this possible or am I asking the wrong
> question?
>
> When I am debugging (in Visual Studio) by looking 'into' the sender ->
> System.Web.UI.WebControls.Button -> CommandName I can see what the
> command name is. How do I get this CommandName?
>
> Any help greatly appreciated.
> Mike



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Non-code behind to code behind John ASP .Net 2 02-19-2007 07:08 PM
Trigger CommandName from DropDownList in GridView Irfi ASP .Net 0 12-15-2005 04:58 PM
Trigger CommandName from DropDownList in GridView Irfi ASP .Net 0 12-15-2005 04:58 PM
asp:linkbutton - commandname behaviour John Blair ASP .Net 2 12-30-2004 05:04 PM
Re: Code Behind vs. no code behind: error Ben Miller [msft] ASP .Net 1 06-28-2003 01:46 AM



Advertisments