Hi
I have below code and i have written in every Aspx page where required. Can it be written at one place from where it can be called.
Suppose i want to change name from Add to Create it has effect on all pages of the project.
Thanks
Hi
I have below code and i have written in every Aspx page where required. Can it be written at one place from where it can be called.
Suppose i want to change name from Add to Create it has effect on all pages of the project.
Thanks
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.
Naimish MakwanaPosted Sep 2, 2024, 10:56 AM
Yes, you can definitely centralize this code to make it easier to manage and update. One way to achieve this is by creating a user control or a reusable component that you can include in your ASPX pages. Here’s how you can do it:
ButtonControl.ascx).ButtonControl.ascx.cs): Add any necessary logic in the code-behind file.By doing this, you only need to update the text in the user control, and it will reflect across all pages where the control is used. This approach makes your code more maintainable and reduces redundancy.
Thanks
Aman GuptaPosted Sep 2, 2024, 10:55 AM
Hi Ramco,
1. Create a User Control (ASCX):
AddButton.ascx.AddButton.ascx:
2. Use the User Control in Your ASPX Pages:
Example ASPX Page:
3. Modify Button Text (Optional):
If you want to change the button text on specific pages, you can expose a public property in the user control.
AddButton.ascx.cs:
Example ASPX Page:
This way, you only need to modify the markup in one place, and any changes will automatically be reflected in all the pages where the control is used.