Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created DataList in my asp.net page. The Datalist has an OnItemCommand (i.e OnItemCommand="EquipmentsListDatalist_ItemCommand"). When ever i refresh my page, the method EquipmentsListDatalist_ItemCommand is getting invoked. is there any option to stop calling EquipmentsListDatalist_ItemCommand method from page load.

Here is my coding :


asp :

<asp:DataList ID="SampleDataList"  runat="server" onItemCommand="EquipmentsListDatalist_ItemCommand" DataKeyField="productModel">
///
///
///
 </ asp:DataList>


c# :
C#
public void EquipmentsListDatalist_ItemCommand(Object sender , Eventargs e)
{
///
///
///
}


I have not meant anything regarding this method in Page_Load method. But still this method is getting called whenever the Page Load happens. Can anyone please update me why this happens and how to avoid this.

Sorry,if my communication is poor.

Thanks in advance for your help :)
Posted
Updated 6-Jan-14 6:25am
v4
Comments
ZurdoDev 6-Jan-14 12:06pm    
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datalist.itemcommand%28v=vs.100%29.aspx

"Occurs when any button is clicked in the DataList control." Are you clicking a button or somehow invoking the click event? Also, check the call stack to see if it gives a clue.
SRK90 6-Jan-14 12:33pm    
i am clicking a button.
ZurdoDev 6-Jan-14 12:39pm    
In the datalist? If so, that's what it is supposed to do.
SRK90 7-Jan-14 11:12am    
yeah I have updated the method argument....I have a listaray which will get updated whenever this method is called..... but since this method is getting called during Page Load, the listarray is getting updated that time too ... is there any option to avoid this? .... does this make sense ?

1 solution

First of all, the Event Argument is wrong.
C#
public void EquipmentsListDatalist_ItemCommand(Object sender , Eventargs e)
{
}

Should be...
C#
public void EquipmentsListDatalist_ItemCommand(Object sender , DataListCommandEventArgs e)
{
}


Reference - DataList.ItemCommand Event[^]

If you click on any button inside DataGrid, then this Event gets fired.
 
Share this answer
 
v2
Comments
SRK90 7-Jan-14 11:12am    
yeah I have updated the method argument....I have a listaray which will get updated whenever this method is called..... but since this method is getting called during Page Load, the listarray is getting updated that time too ... is there any option to avoid this? .... does this make sense ?
This event is fired when any command is given to the DataGrid.

If it is executed at the Page Load, then there is some problem. Can you post the Page Load code here?
SRK90 9-Jan-14 12:49pm    
This method will get invoked whenever page load happens. I have done an alternative way to get a solution for my problem now and its working good as expected... little late but still a worthy go... Thanks for involving in helping me :)
SRK90 9-Jan-14 12:54pm    
This method will get invoked when ever the Page Load happens. I have found an alternative way in my codings and got a solution for my problem... now its working fine as expected... Little late but still a worthy go ... Thanks for putting yourself in helping me :)
Anyway, good work. :)

Please don't forget to mark this as answer.

Thanks,
Tadit

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900