filmov
tv
Adding using user controls on a webform Part 105
Показать описание
Text version of the video
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
Slides
All ASP .NET Text Articles
All ASP .NET Slides
All Dot Net and SQL Server Tutorials in English
All Dot Net and SQL Server Tutorials in Arabic
In the previous video, we discussed about creating a calendar user control. Please watch Part 104, before proceeding with this video. In this video we will discuss about
1. Adding and using user controls on a webform
2. Adding properties to the user control
Adding and using user controls on a webform
Adding user controls to a web page is very straight forward. Simply drag the user control from solution explorer and drop it on the web page. Make sure, the "Design" view of the webform is selected before dragging and dropping the user control on the webform. This will automatically,
1. Add a "Register" directive for the user control and
2. The control declaration
At this point, you get the following error, if both, the user control and the webform are in the same directory. This limitation is by design due to an internal design consideration for performance.
Adding properties to the user control:
A user control can also have it's own properties and methods. At the moment, CalendarUserControl does not expose any property that returns the selected date.
For example, drag and drop a button control on the same webform. when I click this button, we want to print the selected date. To do this let's add the following SelectedDate property for the CalendarUserControl.
public string SelectedDate
{
get
{
return txtDate.Text;
}
set
{
txtDate.Text = value;
}
}
On the webform, in the button click event, I should now be able to retrieve, the selected date using "SelectedDate" property of the "CalendarUserControl" as shown below.
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(CalendarUserControl1.SelectedDate);
}
You can also set this property declaratively in the HTML at design time. When the webform, loads, it shows the date, that we have set.
But one limitation, here with the user control, is that the design time value is not shown in the control at design time. This is by design, and there are 2 ways to solve this issue.
1. Create a custom control instead of user control.
2. Compile the user control into a DLL.
We will be discussing about these in later video sessions.
In the next video session we will discuss about adding "events" to our "CalendarUserControl"
For the HTML and code samples used in the demo please visit my blog at the following link
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
Slides
All ASP .NET Text Articles
All ASP .NET Slides
All Dot Net and SQL Server Tutorials in English
All Dot Net and SQL Server Tutorials in Arabic
In the previous video, we discussed about creating a calendar user control. Please watch Part 104, before proceeding with this video. In this video we will discuss about
1. Adding and using user controls on a webform
2. Adding properties to the user control
Adding and using user controls on a webform
Adding user controls to a web page is very straight forward. Simply drag the user control from solution explorer and drop it on the web page. Make sure, the "Design" view of the webform is selected before dragging and dropping the user control on the webform. This will automatically,
1. Add a "Register" directive for the user control and
2. The control declaration
At this point, you get the following error, if both, the user control and the webform are in the same directory. This limitation is by design due to an internal design consideration for performance.
Adding properties to the user control:
A user control can also have it's own properties and methods. At the moment, CalendarUserControl does not expose any property that returns the selected date.
For example, drag and drop a button control on the same webform. when I click this button, we want to print the selected date. To do this let's add the following SelectedDate property for the CalendarUserControl.
public string SelectedDate
{
get
{
return txtDate.Text;
}
set
{
txtDate.Text = value;
}
}
On the webform, in the button click event, I should now be able to retrieve, the selected date using "SelectedDate" property of the "CalendarUserControl" as shown below.
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(CalendarUserControl1.SelectedDate);
}
You can also set this property declaratively in the HTML at design time. When the webform, loads, it shows the date, that we have set.
But one limitation, here with the user control, is that the design time value is not shown in the control at design time. This is by design, and there are 2 ways to solve this issue.
1. Create a custom control instead of user control.
2. Compile the user control into a DLL.
We will be discussing about these in later video sessions.
In the next video session we will discuss about adding "events" to our "CalendarUserControl"
For the HTML and code samples used in the demo please visit my blog at the following link
Комментарии