crackyourinterview.com


To improves our performance please Like Share Subscribe(Will boost us)

Run Server Side code from javascript with dopostback method
Question Posted on 28 Aug 2011Home >> JavaScript >> JavaScript Questions >> Run Server Side code from javascript with dopostback method

Run server side code from javascript with dopostback method
There are some cases when we need to call server side functionality from javascript so we have to go for dopostback method and that server side code must bind to any event so that we can able to call the code part.To get clear this we take a example of div tag :-

(1)Javascript Function :-
function CallServerCode
{
__doPostBack('divLoad', 'TestCode');

}

ABove divload is the id of div tag and we create a onload event to get execute from javascript

(2)Bellwo is the html code for div tag
< div id="divLoad" runat="server" onload="divLoad_Onload" />

(3)Now C# code for event onload

protected void divLoad_Onload(object sender, EventArgs e)
{
  this.Page.ClientScript.GetPostBackEventReference(this, string.Empty);
  if (this.Page.IsPostBack)
  {
   string eventTarget = (this.Request["__EVENTTARGET"] == null ? string.Empty : this.Request["__EVENTTARGET"]);
   string eventArgument = (this.Request["__EVENTARGUMENT"] == null ? string.Empty : this.Request["__EVENTARGUMENT"]);
   if (eventArgument != "" && (eventArgument == "Test")
    {
     // Here you can write your server side logic
     eventArgument = "";
    }
  }
}

in the above code for each server postback it will check for the argument but when dopostback method from javascript is called then the argument will be matched so that your logic will be excuted.
0
0



.


Most Visited Questions:-

Deep Learning Questions Answers
Below are the different Deep Leaning Questions and answer a More...

Continuous Integration Questions Answers
Below are the 20 odd questions for CI or Continuous Integra More...

Derived relationships in Association Rule Mining are represented in the form of __________.
Derived relationships in Association Rule Mining are repres More...

What is Gulpjs and some multiple choice questions on Gulp
Gulpjs is an open source whihc helps in building Javascript More...

Microservices Architecture Questions Answers
Below are the different questions on Microservices Architec More...




Other Important Questions

regular expression for credit card like VISA, MASTER, AMEX

How to remove item from dropdownlist in Javascript

Different Data Types in Javascript in 2015?

syntax to get dropdownlist text in javascript

The snippet that has to be used to check if “a” is not equal to “null” is _________






@2014-2022 Crackyourinterview (All rights reserved)
Privacy Policy - Disclaimer - Sitemap