Hi
I want to define below code at only 1 place. Asof now i am writing it in each form. How it can be done through User Control . I have i User Control whose code is
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MBox.ascx.cs" Inherits="Payroll.MBox" %>
Ramco RamcoPosted Aug 23, 2024, 10:21 AM
Hi Aman
How i will check at server side that User Has pressed Delete button or Cancel button
Thanks
Aman GuptaPosted Aug 23, 2024, 10:10 AM
To centralize the code for the modal popup and the JavaScript functionality into a single place, you can use a User Control in ASP.NET. Here's a step-by-step guide on how you can do this:
Define the User Control:
You've already created a User Control
MBox.ascx. You should include the common JavaScript and modal HTML code in this file. Make sure the JavaScript is enclosed in script tags and that the modal HTML structure is correctly placed inside the user control.MBox.ascx:Use the User Control in Your Pages:
Now, you can include this User Control in any page where you need the modal popup functionality. To do this, you need to register the User Control in your page and then include it where needed.
In your .aspx page:
Call the JavaScript Function from Your Code-Behind:
To trigger the JavaScript function from your code-behind, you can use
ScriptManager.RegisterStartupScriptto call theShowPopup_Redirectfunction.In your .aspx.cs page:
Ensure Your JavaScript Libraries Are Included:
Make sure that your page includes any required JavaScript libraries such as SweetAlert. You might include these libraries in your Master Page or specific pages where needed.
By centralizing the modal code in a User Control, you reduce duplication and make your codebase easier to maintain.
Ramco RamcoPosted Aug 23, 2024, 10:06 AM
Hi Aman
Can you plase provide me full sample as per above code. That is also User Control
Thanks
Aman GuptaPosted Aug 23, 2024, 10:01 AM
Hi Ramco,
To centralize the code for the modal popup and the JavaScript functionality into a single place, you can use a User Control in ASP.NET. Here's a step-by-step guide on how you can do this:
Define the User Control:
You've already created a User Control
MBox.ascx. You should include the common JavaScript and modal HTML code in this file. Make sure the JavaScript is enclosed in script tags and that the modal HTML structure is correctly placed inside the user control.Use the User Control in Your Pages:
Now, you can include this User Control in any page where you need the modal popup functionality. To do this, you need to register the User Control in your page and then include it where needed.
Call the JavaScript Function from Your Code-Behind:
To trigger the JavaScript function from your code-behind, you can use
ScriptManager.RegisterStartupScriptto call theShowPopup_Redirectfunction.Ensure Your JavaScript Libraries Are Included:
Make sure that your page includes any required JavaScript libraries such as SweetAlert. You might include these libraries in your Master Page or specific pages where needed.
Hope this helps you Ramco.
Thanks