如何将值从java脚本传递到c#.net ....? [英] How to pass the values from java script to c#.net....?

查看:65
本文介绍了如何将值从java脚本传递到c#.net ....?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的代码



 FB.Event.subscribe(&#39 ; auth.statusChange',function(response)
{
if (response.authResponse)
{

// 用户已认证您的应用并登录Facebook
var uid =& quot; http: // graph.facebook.com/" + response.authResponse.userID +& quot; / picture& quot ;;
FB.api(' / me& #39;,function(me){

document.getElementById(auth-displayname;)。innerHTML = me.name;
document.getElementById(Email).innerHTML = me.email;
document.getElementById(profileImg&)。src = uid;

// document.getElementById(' testserver')。click();
// document.getElementById(hdnResultValue).value = me.name;
document.getElementById(testserver&)。click();
document.getElementById('& lt;%= hdnName.ClientID%& gt;')。 value = me.name;
document.getElementById('& lt;%= hdnEmailAddress.ClientID%& gt;')。 value = me.email;
document.getElementById(' hdnfbid')。 value = me.id;



})< / pre >
}
< pre lang = xml>< asp:HiddenField ID = hdnName Value = 0 runat = server />
< asp:HiddenField ID = hdnEmailAddress Value = 0 runat = 服务器 />
< asp:HiddenField ID = hdnfbid Value = 0 runat = 服务器 />
<% - < asp:HiddenField ID = hdnResultValue值= < span class =code-string> 0 runat = server /> - %>
< asp:button runat = server text = 按钮 id = testserver OnClick = fbdetails />





aspx.cs页面:



我在中传递值 c#.net如下所示,但价值没有得到......?请给我回答

protected void fbdetails( object sender,EventArgs e)
{

string codeBehindValue = hdnName.Value;
string codeBehindValue1 = hdnEmailAddress.Value;
string codeBehindValue1 = hdnfbid.Value;


}

解决方案

嘿..

使用HTML输入字段将值从javascript传递到c#代码后面..

看看下面的示例:



 <  输入    type   =  hidden    id   =  hiddenID    runat   =  server    /  >  



  function  C allMe()
{
document .getElementById(' hiddenID')。value = OK;
}



C#代码落后:



  protected   void  Page_Load()
{
if (hiddenID.Value == OK
{
Response.Write( 从Javascript传递给Code Behind的值);
}

}





试试吧......



问候

Anurag


[ ^ ]。

Hi
This is my code

FB.Event.subscribe(&#39;auth.statusChange&#39;, function (response)
         {
             if (response.authResponse)
            {

                // user has auth&#39;d your app and is logged into Facebook
                var uid = &quot;http://graph.facebook.com/&quot; + response.authResponse.userID + &quot;/picture&quot;;
                FB.api(&#39;/me&#39;, function (me) {

                    document.getElementById(auth-displayname;).innerHTML = me.name;
                    document.getElementById(Email).innerHTML = me.email;
                    document.getElementById(profileImg&).src = uid;

                    //                     document.getElementById(&#39;testserver&#39;).click();
                    //  document.getElementById(hdnResultValue).value = me.name;
                    document.getElementById(testserver&).click();
                    document.getElementById(&#39;&lt;%= hdnName.ClientID %&gt;&#39;).value = me.name;
                    document.getElementById(&#39;&lt;%= hdnEmailAddress.ClientID %&gt;&#39;).value = me.email;
                    document.getElementById(&#39;hdnfbid&#39;).value = me.id;



                })</pre>
}
<pre lang="xml"><asp:HiddenField ID="hdnName" Value="0" runat="server" />
 <asp:HiddenField ID="hdnEmailAddress" Value="0" runat="server" />
 <asp:HiddenField ID="hdnfbid" Value="0" runat="server" />
  <%--<asp:HiddenField ID="hdnResultValue" Value="0" runat="server" />--%>
     <asp:button runat="server" text="Button" id="testserver" OnClick="fbdetails"/>



aspx.cs page:

I am passing values in c#.net given below but values are not getting...? please give me answer

protected void fbdetails(object sender, EventArgs e)
        {
          
            string codeBehindValue = hdnName.Value;
            string codeBehindValue1 = hdnEmailAddress.Value;
            string codeBehindValue1 = hdnfbid.Value;


        }

解决方案

Hey..
use HTML input field to pass values from javascript to c# code behind..
Have a look at the sample below:

<input type="hidden" id="hiddenID" runat="server" />


function CallMe()
{
document.getElementById('hiddenID').value="OK";
}


C# code behind:

protected void Page_Load()
{
if(hiddenID.Value=="OK")
{
Response.Write("Value passed from Javascript to Code Behind");
}

}



Try it...

Regards
Anurag


A similar question was answered before[^].


这篇关于如何将值从java脚本传递到c#.net ....?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆