Hi
I have below control. I want where code behind of below line to be added. Is it to be defined in User Control Or Web Form from where modal popup has been called.
Form Department
htmlTable.Append("");
htmlTable.Append("");
User Control
Thanks
3 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Aman GuptaPosted Aug 27, 2024, 5:38 AM
Hi Ramco,
The
lnkRecordDelete_Clickevent handler should be added in the code-behind file of the User Control if theLinkButtonis part of the User Control.Here’s how you can structure it:
User Control Code-Behind (e.g.,
YourUserControl.ascx.cs):Web Form Code-Behind (e.g.,
YourWebForm.aspx.cs): If theLinkButtonis part of a User Control, the event handler is generally defined in the User Control’s code-behind. The Web Form’s code-behind would not need this handler unless you want to handle the delete action from the Web Form, in which case you would need to bubble the event from the User Control to the Web Form.If the
LinkButtonis directly in the Web Form, then place thelnkRecordDelete_Clickmethod in the Web Form’s code-behind.So, place the
lnkRecordDelete_Clickmethod in the code-behind of where theLinkButtonresides—most likely the User Control in your scenario.Gowtham CpPosted Aug 27, 2024, 4:55 AM
Hi Ramco,
You should define the
lnkRecordDelete_Clickmethod in the code-behind file of your User Control (MBox.ascx.cs). Here’s a clearer breakdown:1. User Control (.ascx) In your User Control markup, you have the
LinkButtonthat triggers the delete action:2. User Control Code-Behind (MBox.ascx.cs) You need to add the
lnkRecordDelete_Clickmethod in the code-behind file (MBox.ascx.cs) where you handle the delete logic. Here’s a sample implementation:3. Including the User Control in Your Web Form Make sure your User Control is correctly included in the Web Form from which it is being used. For example:
This setup ensures that the
lnkRecordDelete_Clickmethod is properly linked to theLinkButtonin your User Control.Let me know if you need any more details or further assistance!
Naimish MakwanaPosted Aug 27, 2024, 4:49 AM
To determine where to add the code-behind for the
LinkButton, consider the following:User Control: If the
LinkButtonis part of a User Control, the event handlerlnkRecordDelete_Clickshould be defined within the code-behind file of that User Control. This keeps the logic encapsulated within the control, making it reusable across different pages.Web Form: If the
LinkButtonis directly on a Web Form (e.g., an ASPX page), the event handler should be defined in the code-behind file of that Web Form. This is appropriate if the control is specific to that page and not intended for reuse.Given your context, it seems the
LinkButtonis part of a modal defined within a User Control. Therefore, you should define thelnkRecordDelete_Clickevent handler in the code-behind file of the User Control.Here’s an example of how you might define the event handler in the User Control’s code-behind file:
Thanks