Hi All,
I got a functionality like below. Please share your experience or thoughts.
I have a user control and it has one text box and 2 buttons (add, remove). User control will be added dynamically based on functionality. But How to know add, remove id controls in .aspx (Page_load) function to know which button user has clicked?
If anybody has real time experience on this please share your thoughts and please do not provide any links as i already googled in the internet.
Regards,
Sudheer


Joginder BangerRank #360 · 7K reputationPosted Nov 30, 2014, 11:51 PM EST
try this code may be it help. I have testing this code on my machine.
if (IsPostBack )
{
if (!string.IsNullOrEmpty(Request.Form[Button1.UniqueID]))
{
var text = "Button 1 clicked";
}
if (!string.IsNullOrEmpty(Request.Form[Button2.UniqueID]))
{
var seondtext = "Button 2 clicked";
}
}
Kunal VaishyaRank #990 · 2K reputationPosted Dec 2, 2014, 7:49 PM EST
If you want to implement click event in client then you can use "closest" function of Jquery, which is help you to find nearest control.
Example:
$(document).ready(function(){
$("span").closest("ul").css({"color":"red","border":"2px solid red"});
});
Reference : http://www.w3schools.com/jquery/traversing_closest.asp
Regards,
Kunal.