Adding using user controls on a webform Part 105

preview_player
Показать описание
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
Рекомендации по теме
Комментарии
Автор

Thank you so much for providing the amazing presentations. You are making my understanding much deeper and better.

amritgopali
Автор

Thanks a ton! for the videos. It's super easy to follow and great explanation. Anyone can pick up asp.net real quick with these intuitive videos!! Thanks again!

meghu
Автор

Thank you very much for all your videos. I have learned a lot. thanks again. you are the best teacher

pamdavila
Автор

Sir u r really great we are learning a lot from you, god has given gift like this for me

ashokkumargajula
Автор

Thank you very much for taking time to give feedback. In the description of this video, I have included the link for ASP .NET, C#, and SQL Server playlists. All the videos are arranged in logical sequence in these playlists, which could be useful to you. Please share the link with your friends who you think would also benefit from them. If you like these videos, please click on the THUMBS UP button below the video. For email alerts, when new videos are uploaded, you may subscribe to my channel.

Csharp-video-tutorialsBlogspot
Автор

Thank you for these valuable videos! It is very easy to follow and understand your presentation.

gabornemes
Автор

Fantastic, this really helps me with what I need to know for my job, thank you.

kaminari
Автор

it's so great! Thank you so much for your videos.

phuongvunguyen
Автор

Hi Venki, sure, we will discuss master pages very soon. Thank you for your patience.

Csharp-video-tutorialsBlogspot
Автор

you have the light blaze for my blind eyes of programming since years

TheManubarcafan
Автор

Hi Sir I am getting an error when I put an existing UserDefinedControl in a new Folder. I changed the namespace in the code behind file also. But I am unable to accessible the property That I have created in UserControl.

madhusudansharma
Автор

Why would I want to register the user control in web.config file
While it's already auto generated just by drag-dropping the user control to design tab of the aspx file of the webform?

youssufmostafa
Автор

sir i have a main page
i have add 2web user control to the main page of type aspx 1.login with form runat = server & 2.register with form runat = server .
an exception arised "System.Web.HttpException: A page can have only one server-side Form tag."

sachinm
Автор

Hi Sir Thanks for sharing videos related .Net platform. i am requesting you please make a video on MASTER Page in Asp.Net .Thanks in Advance.

bidata
Автор

one thing I don't understand

in the VS toolbox, there is calendar (besides button, textbox...)

can we just drag and drop that calendar to use it ?!

ciscoinch
Автор

After i placed the CalenderUserControl in folder and running the webForm it gives me
HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory.

I tried to slove the problem by enabling Directory browsing true . But actually the files in directory are showing but not the webform

MrSandeep
Автор

How to validate the registration form created in user control...

urmilachaudhari
Автор

I mess up my VS solution file -- this is difficult

before that, I got 7 same error about repeating something in web.config file and it does not look as simple as his web.config file,   GIVE UP this video

ciscoinch