I didn’t get a time to write something here for a long time. Yes I can say I was busy. (But I was not :)) Anyway I thought to write about something finally and I promise (this is a serious promise) that I will try to do something (do a posting actually) on my blog more frequently.
The ability to call the web methods by JavaScript on .net is very very useful and we can implement the web pages more efficiently by using this. For example we do not need to send whole page and update. Yes this is AJAX (that what I think).
Here is a web method example. It should be on the aspx page code behind and should be a static (shared) method. I have tried to insert the web methods on user controls and was unable to do so (if you know a way please share with us). This is on VB.net.
GetMyData method will create a Student entity based on the IDs passed in and this method can even call to DB to get the data (since this is on server side we can do anything).
Then this method (GetMyData) needs to be executed by JavaScript. Here is the example on how to do that.
In here if you have noticed I have send 2 more parameters (_this.UpdateStudentFields, _this.ServiceError) than the web method accepts. (Was not by any mistake:))
_this.UpdateStudentFields – is the JavaScript method name that will execute when we returned from the web method. So basically what happens is Student entity will be passed into this method (UpdateStudentFields) as the result. So then we can do anything by JavaScript by using this result entity.
_this.ServiceError – this is the javascript method name that executes if there were any exceptions. So then we can do anything even with the error (exception actually). I prefer to show the errors to the end user (swallowing exeptions is not a good practice).
Hope this was helpful and if there is any issues or if you know a better way to impliment this please leave a comment.
The ability to call the web methods by JavaScript on .net is very very useful and we can implement the web pages more efficiently by using this. For example we do not need to send whole page and update. Yes this is AJAX (that what I think).
Here is a web method example. It should be on the aspx page code behind and should be a static (shared) method. I have tried to insert the web methods on user controls and was unable to do so (if you know a way please share with us). This is on VB.net.
_ Public Shared Function GetMyData(ByVal studentID As Integer, ByVal schoolID As Integer) As Student Dim studentService As New StudentService() Dim result As Student = studentService.GetStudent(studentID, schoolID) Return result End Function
GetMyData method will create a Student entity based on the IDs passed in and this method can even call to DB to get the data (since this is on server side we can do anything).
Then this method (GetMyData) needs to be executed by JavaScript. Here is the example on how to do that.
this.GetStudent = function(args) { PageMethods.GetMyData(_studentID, _ schoolID, _this.UpdateStudentFields, _this.ServiceError); }
In here if you have noticed I have send 2 more parameters (_this.UpdateStudentFields, _this.ServiceError) than the web method accepts. (Was not by any mistake:))
_this.UpdateStudentFields – is the JavaScript method name that will execute when we returned from the web method. So basically what happens is Student entity will be passed into this method (UpdateStudentFields) as the result. So then we can do anything by JavaScript by using this result entity.
this. UpdateStudentFields = function(result) { if (result.Succeeded) { //assign the values to the fields //studentname = result.Name; } }
_this.ServiceError – this is the javascript method name that executes if there were any exceptions. So then we can do anything even with the error (exception actually). I prefer to show the errors to the end user (swallowing exeptions is not a good practice).
this.ServiceError = function(error) { //this will show the error on page // AddError method should be implimented to do so … AddError(error.get_message()); }
Hope this was helpful and if there is any issues or if you know a better way to impliment this please leave a comment.
ReplyDeleteIt seems you are so busy in last month. The detail you shared about your work and it is really impressive that's why i am waiting for your post because i get the new ideas over here and you really write so well.
Selenium training in Chennai
Thanks to the admin for sharing this blog as I am able to get an idea of more updates in a clear way.
ReplyDeleteComputer Education Franchise
Education Franchise India
Computer Center Franchise
Education Franchise Opportunities in India
Education Franchise India
Spoken English Franchise
Franchise For Spoken English Classes
Top Education Franchise in India
Best Education Franchise in India
vidmate app
ReplyDeleteGood Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.thanks for your information really good and very nice web design company in velachery web design company in chennai
ReplyDeleteYour topic is very nice and helpful to us … Thank you for the information you wrote.
ReplyDeleteLearn Hadoop Training from the Industry Experts we bridge the gap between the need of the industry. Softgen Infotech provide the Best Hadoop Training in Bangalore with 100% Placement Assistance. Book a Free Demo Today.
Big Data Analytics Training in Bangalore
Tableau Training in Bangalore
Data Science Training in Bangalore
Workday Training in Bangalore
Learn Hadoop Training from the Industry Experts we bridge the gap between the need of the industry. Softgen Infotech provide the Best Hadoop Training in Bangalore with 100% Placement Assistance. Book a Free Demo Today.
Big Data Analytics Training in Bangalore
Tableau Training in Bangalore
Data Science Training in Bangalore
Workday Training in Bangalore
ReplyDeleteThanks for sharing this Informative content. Well explained. Got to learn new things from your Blog devops training in chennai | devops training in anna nagar | devops training in omr | devops training in porur | devops training in tambaram | devops training in velachery
Very helpful contents -
ReplyDeletePHP contact form with CAPTCHA and validation
Face Recognition OpenCV Source Code
PHP Send Email Using SMTP
Python parse XML with lxml library
Python program to find the frequency of each element in the array
good to read something like this xbox gift card codes
ReplyDelete