简体   繁体   中英

How to run Facebook Social Plugin Javascript From CodeBehind C#?

I have a website where i want my visitors to invite their friends. I'm using the Requests Dialog for this. But now i want to add a dynamic text message to this invite.

The dynamic text is generated in an c# code behind file. But the Request Dialog is triggered with javascript.

Here is the Request Dialog part on my aspx page:

  <div id="fb-root"></div>
  <script src="http://connect.facebook.net/nl_NL/all.js">
  </script>
  <script>
      FB.init({
          appId: '[MY-APP-ID]', cookie: true,
          status: true, xfbml: true
      });

      function inviteFriends() {
          FB.ui({ method: 'apprequests', message: '[THE DYNAMIC MESSAGE I WANT TO SEND]', data: 'tracking information for the user' });
      }


  </script>

Is it possible to call this javascript form codebehind code and pass the message parameter too?

Thanks in advance!

You can use <%=... %> to expose your code to page (assuming you have message in requestsDialogMessage variable):

FB.ui({
  method: 'apprequests',
  message: '<%= requestsDialogMessage %>',
  data: 'tracking information for the user'
});

Other way may be exposing the message to some JavaScript variable and using it within FB.ui call:

<script>
  var exposedData = {
    requestsDialogMessage: '<%= requestsDialogMessage %>'
  };
</script>

And later in your JS code:

FB.ui({
  method: 'apprequests',
  message: exposedData.requestsDialogMessage,
  data: 'tracking information for the user'
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM