Use of Delegate to call RoleCheckBox_CheckChanged

Posted by Ashokn under C# on 12/7/2010 | Points: 10 | Views : 1543 | Status : [Member] | Replies : 1

I have a ChkBox in Repeater control as below:=
<asp:Repeater ID="UsersRoleList" runat="server">
<asp:CheckBox runat="server" ID="RoleCheckBox" AutoPostBack="true" Text='<%# Container.DataItem %>' OnCheckedChanged="RoleCheckBox_CheckChanged" />
<br />

And onCheck of ChkBox item ,below event is fired.

protected void RoleCheckBox_CheckChanged(object sender, EventArgs e)
//Chked Role is added to DB.
Roles.AddUserToRole(selectedUserName, roleName);

But I want this event to fire on Click of some Button.
Can I use DELEGATE to achieve this??

Please modify below coding...
//Declaring delegate
public delegate void UpdateUserRole(object sender, EventArgs e);
// Instantiation
UpdateUserRole MyDelegate = new UpdateUserRole(RoleCheckBox_CheckChanged);
// Invocation

Thanks in advance...


Posted by: SheoNarayan on: 12/7/2010 [Administrator] HonoraryPlatinum | Points: 25

If I understand your question correctly, why do n't you remove "OnCheckedChanged="RoleCheckBox_CheckChanged" " from the checkbox so that it will not fire on the check of the checkbox.

Declare a button and specify this event to fire on the click event
<asp:Button runat="Server" id="Fd" onclick="RoleCheckBox_CheckChanged" Text="Submit" />

This is very simple wondering if this is what you are looking for or possibly I couldn't understand your problem.

Thanks and hope this will help.

Sheo Narayan

Ashokn, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response