Often we need some code to be executed in hosting page in response to some action in User control.
Say for example, your Page is having a Country dropdown, and also placed a user control having interface to allow users to add a new country in underlying data store. What you really require is to reload your Country dropdown as soon as user adds/edits a country through the user control.
This article will explain how to write custom events in user controls and to handle them in the hosting page in order to achieve this:
A. Changes to be done in Add/Edit Country User control.
- Declare an event handler in your Country user control.
public event System.EventHandler CountryAdded;
- Jump to the "Save" button code (or ItemInserted/ ItemUpdated event, if you are using ObjectDataSource).
Add following lines after completion of Save operation code.
if (this.CountryAdded != null)
{
this.CountryAdded(this, new EventArgs());
}
This is all you need to do in User control to make the control responsive to "CountryAdded" event.
B. The last step is a very straight forward - Just write event handler in your hosting page, and there you need to rebind your DropDownList.
Once done, you should now be able to see Country dropdown in your page gets reloaded as and when a Country is added/ edited through User control on that page.
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2012
(49)
-
▼
April
(24)
- Get only Date part for SQL Server DateTime value
- Membership in ASP.NET MVC 4 (System.Web.Providers)
- Binding two or more types of objects (models) to s...
- Implement Custom Validation in ASP.NET MVC
- Simple client-side Validations using ASP.NET MVC
- Investigation: Values do not retain in model while...
- Data Binding to RadioButton in a View in MVC
- Investigation: SelectedIndexChanged not firing for...
- Investigation: ExecuteNonQuery() always returns -1
- Development and Deployment - Troubleshooting, Inve...
- Print Page Content to printer (or virtual print ou...
- Show long text in Tooltip
- Auto login into Team system with your authorized c...
- Visual Studio .NET - Some handy shortcuts
- Write custom events for User Controls in ASP.NET
- SQL Query to return each date of month in each dif...
- How to debug ASP.NET Windows Service
- FIX: Add a 32-bit SQL Server 2000 as a Linked serv...
- Difference between integer Cast and Convert in C#
- Optimizing SQL Code by replacing IF..ELSE with CAS...
- Check Authentication Mode in ASP.NET
- How to validate a page using Java script
- SQL Query - To search for a column (by column name...
- C#.NET - Difference between Convert.ToString(), .T...
-
▼
April
(24)
No comments:
Post a Comment
Thanks for visiting my blog.
However, if this helped you in any way, please take a moment to write a comment.
Thanks
Nirman