473,385 Members | 1,370 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

The name of the type of control

I have button in asp:repeater control.

<asp:Button Runat=server ID=btnPList Text="..." CommandArgument='<%#
DataBinder.Eval(Container.DataItem,"datumP")%>'></asp:Button>

In code behind I use the item-command event of data repeater:

Private Sub rprPlists_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.RepeaterCommandEventArgs ) Handles
rprPlists.ItemCommand

If e.CommandSource.GetType.Name.ToString() = "Button" Then
.......
end if

end sub

How can I do the same in C#?

I can't get the name of the command who fired the event.
The CommandSource.GetType.Name.ToString() doesn't work.

protected void rprPlists_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
if (e.CommandSource.GetType.Name.ToString() == "Button"){
.....}
}
Any idea?
regards,S
Nov 19 '05 #1
3 1931
This is how I did it:

In the aspx page, here's my button definition:

<asp:Button id="cmdRemoveMsg" runat="server" Text="Remove"
CommandArgument="<%# ((MyCustomClass)Container.DataItem).ID %>"
CommandName="Remove"></asp:Button>

In the code behind, first hook to the repeater's event:

this.rptrMessages.ItemCommand += new
System.Web.UI.WebControls.RepeaterCommandEventHand ler(this.rptrMessages_ItemCommand);

Finally, here's my handler:

private void rptrMessages_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
string commandName = e.CommandName;
string commandArg = e.CommandArgument;
//Do stuff
}

Hope that helps.

"simon" wrote:
I have button in asp:repeater control.

<asp:Button Runat=server ID=btnPList Text="..." CommandArgument='<%#
DataBinder.Eval(Container.DataItem,"datumP")%>'></asp:Button>

In code behind I use the item-command event of data repeater:

Private Sub rprPlists_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.RepeaterCommandEventArgs ) Handles
rprPlists.ItemCommand

If e.CommandSource.GetType.Name.ToString() = "Button" Then
.......
end if

end sub

How can I do the same in C#?

I can't get the name of the command who fired the event.
The CommandSource.GetType.Name.ToString() doesn't work.

protected void rprPlists_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
if (e.CommandSource.GetType.Name.ToString() == "Button"){
.....}
}
Any idea?
regards,S

Nov 19 '05 #2
Hi Andy,

thank you for your answer.
I know you can do that by assigning CommandName="Remove", but I would like
to catch the tag name of the control,
so "button".

In VB, it works as you can see in my example.

Now I would like to achive the same with C# (also for some other purposes).
Do you know how?

Regards,Simon

"Andy Luksic" <An********@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
This is how I did it:

In the aspx page, here's my button definition:

<asp:Button id="cmdRemoveMsg" runat="server" Text="Remove"
CommandArgument="<%# ((MyCustomClass)Container.DataItem).ID %>"
CommandName="Remove"></asp:Button>

In the code behind, first hook to the repeater's event:

this.rptrMessages.ItemCommand += new
System.Web.UI.WebControls.RepeaterCommandEventHand ler(this.rptrMessages_ItemCommand);

Finally, here's my handler:

private void rptrMessages_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
string commandName = e.CommandName;
string commandArg = e.CommandArgument;
//Do stuff
}

Hope that helps.

"simon" wrote:
I have button in asp:repeater control.

<asp:Button Runat=server ID=btnPList Text="..." CommandArgument='<%#
DataBinder.Eval(Container.DataItem,"datumP")%>'></asp:Button>

In code behind I use the item-command event of data repeater:

Private Sub rprPlists_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.RepeaterCommandEventArgs ) Handles
rprPlists.ItemCommand

If e.CommandSource.GetType.Name.ToString() = "Button" Then
.......
end if

end sub

How can I do the same in C#?

I can't get the name of the command who fired the event.
The CommandSource.GetType.Name.ToString() doesn't work.

protected void rprPlists_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
if (e.CommandSource.GetType.Name.ToString() == "Button"){
.....}
}
Any idea?
regards,S

Nov 19 '05 #3
Ah, I see. In that case, use this in the event handler:

e.CommandSource.GetType().Name

"simon" wrote:
Hi Andy,

thank you for your answer.
I know you can do that by assigning CommandName="Remove", but I would like
to catch the tag name of the control,
so "button".

In VB, it works as you can see in my example.

Now I would like to achive the same with C# (also for some other purposes).
Do you know how?

Regards,Simon

"Andy Luksic" <An********@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
This is how I did it:

In the aspx page, here's my button definition:

<asp:Button id="cmdRemoveMsg" runat="server" Text="Remove"
CommandArgument="<%# ((MyCustomClass)Container.DataItem).ID %>"
CommandName="Remove"></asp:Button>

In the code behind, first hook to the repeater's event:

this.rptrMessages.ItemCommand += new
System.Web.UI.WebControls.RepeaterCommandEventHand ler(this.rptrMessages_ItemCommand);

Finally, here's my handler:

private void rptrMessages_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
string commandName = e.CommandName;
string commandArg = e.CommandArgument;
//Do stuff
}

Hope that helps.

"simon" wrote:
I have button in asp:repeater control.

<asp:Button Runat=server ID=btnPList Text="..." CommandArgument='<%#
DataBinder.Eval(Container.DataItem,"datumP")%>'></asp:Button>

In code behind I use the item-command event of data repeater:

Private Sub rprPlists_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.RepeaterCommandEventArgs ) Handles
rprPlists.ItemCommand

If e.CommandSource.GetType.Name.ToString() = "Button" Then
.......
end if

end sub

How can I do the same in C#?

I can't get the name of the command who fired the event.
The CommandSource.GetType.Name.ToString() doesn't work.

protected void rprPlists_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
if (e.CommandSource.GetType.Name.ToString() == "Button"){
.....}
}
Any idea?
regards,S


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Patrick | last post by:
I am dynamically creating TextArea and drop-down lists in ASP.NET using something like HtmlTextArea eachTextArea = new HtmlTextArea(); I tried to set the "name" of these TextAreas, etc. (e.g....
3
by: Anders Jansson | last post by:
Hi all. I have 2 problems when I try to open and convert an ASP.NET VS 2003 web-applikation in VS 2005. In VS 2003 I have no problems at all! First: One subfolder with will not be converted!...
2
by: Shehab Kamal | last post by:
I would lik to instantiate the appropriate control/class given its name, such as: Control c = new Control("TextBox") this should create a new TextBox(). I can write my own code that will create the...
3
by: dcassar | last post by:
I am working on a complex server control that dynamically creates an HtmlInputHidden control that stores its value. As far as the postback process is concerned, this hidden input acts as the...
6
by: Deckarep | last post by:
I want to be able to pass in a function a string say: "TextBox" Then I need a way to convert that string representation into a Type object so i can search through some controls and check their...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
BarryA
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.