How to get javascript values on code behind in c# -


i need javascript values on code behind in c#.i know can use hidden field there no server control on page postback.please tell me how can vales in code behind.

here code:

<html> <head> <title>facebook logged in user details username,email,profile image</title>     <script src="jquery-1.6.2.min.js" type="text/javascript"></script> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> </head> <body> <script>     // load sdk asynchronously        (function (d) {         var js, id = 'facebook-jssdk', ref = d.getelementsbytagname('script')[0];         if (d.getelementbyid(id)) { return; }         js = d.createelement('script'); js.id = id; js.async = true;         js.src = "//connect.facebook.net/en_us/all.js";         ref.parentnode.insertbefore(js, ref);     } (document));      // init sdk upon load     window.fbasyncinit = function () {         fb.init({             appid: 'appid', // app id             channelurl: '//' + window.location.hostname + '/channel', // path channel file             status: true, // check login status             cookie: true, // enable cookies allow server access session             xfbml: true  // parse xfbml         });          // listen , handle auth.statuschange events         fb.event.subscribe('auth.statuschange', function (response) {             if (response.authresponse) {                 // user has auth'd app , logged facebook                 var uid = "http://graph.facebook.com/" + response.authresponse.userid + "/picture";                 fb.api('/me', function (me) {                     document.getelementbyid('auth-displayname').innerhtml = me.name;                     document.getelementbyid('myjsstring').value = me.name;                      alert(document.getelementbyid('myjsstring').value);                      document.getelementbyid('email').innerhtml = me.email;                     document.getelementbyid('profileimg').src = uid;                      //  document.getelementbyid('ctl00_cphdefault_tctps_tpprod_ctl01_tcproduction_tpnewt‌​itlesstatus_changedrowsindiceshiddenfield').value = uid;                    // alert('yyy');                  })                 document.getelementbyid('auth-loggedout').style.display = 'none';                 document.getelementbyid('auth-loggedin').style.display = 'block';             } else {                 // user has not auth'd app, or not logged facebook                 document.getelementbyid('auth-loggedout').style.display = 'block';                 document.getelementbyid('auth-loggedin').style.display = 'none';             }         });         $("#auth-logoutlink").click(function () { fb.logout(function () { window.location.reload(); }); });     }      </script> <h1> facebook login authentication example</h1> <div id="auth-status"> <div id="auth-loggedout"> <div id="result"  class="fb-login-button" autologoutlink="true" scope="email,user_checkins">login</div> </div> <div id="auth-loggedin" style="display: none"> name: <b><span id="auth-displayname"></span></b>(<a href="#" id="auth-logoutlink">logout</a>)<br /> email: <b><span id="email"></span></b><br /> profile image: <img id="profileimg" />  <form runat="server"> <asp:hiddenfield runat="server" id="myjsstring" />  </form> </div> </div> </body> </html> 

you can see there no server control how can name,uid variables in code behind.

thanks

i investigate use of asp.net ajax page methods, because allow script callable stand-alone web services live in .aspx page, this:

page method in code-behind file (call default.aspx discussion's sake):

[webmethod] public static string savedata(string name, string uid) {     // logic here want name , uid values (i.e. save database, call service, etc.) } 

jquery call default.aspx's savedata method:

$.ajax({     type: "post",     url: "default.aspx/savedata",     data: "{'name':'john', 'uid':'abc123'}",     contenttype: "application/json; charset=utf-8",     datatype: "json",     success: function(msg) {         // interesting here.     } }); 

notes: asp.net ajax page methods automatically encode response json not see json serialization in code-behind or serialization logic @ all.

for more information asp.net ajax page methods check out using jquery directly call asp.net ajax page methods


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -