1) You can add them to the attributes of ASP.NET by writing to the server side file(*.cs file)
2) You can add them by writing to the client side file (*.aspx file)
In each way the javascript code should be associated with a client side event is bound to a ASP.NET control.
You can see each way below within an example. In ASP.NET a multiline textbox can not be limited with a max length by just using ASP.NET control attribute panel.
Although I set MaxLength as 15 as you can see below the TextBox1 control could not be limited with the length of 15.
In order to limit multiline textbox you can add the client side attribute of maxLength by writing Asp.Net code in the Page_Load. Therefore while the page is loading this attribute is added to the control.
It is limited with the length of 15. Here is the result :
The second way is writing a script within the aspx file and calling it from a suitable client event. Here onkeyup event is used to call the script.
The result is same. Maximum 15 characters can be written in TextBox1 control.
It is also possible to call the javascript function by adding "onKeyUp" event to the attributes of TextBox1 from cs file as shown below.
TextBox1 has a maximum length of 15 again.
Hiç yorum yok:
Yorum Gönder