调用Java脚本返回值在asp.net code页面 [英] calling java script return value to code page in asp.net

查看:184
本文介绍了调用Java脚本返回值在asp.net code页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的Java脚本函数返回值打电话给我的code结果
我有这样的函数。(这个我在Java脚本写的)

i want to call my java script function return value to my code
i have a function like this..(this i wrote in my java script)

function GetSex()
{

    var sex = EIDAWebComponent.GetSex();
    if(sex == 'M')
        return "Male";
    if(sex == 'F')
        return "Female";
    if(sex == 'X')
        return "Unknown";
}

我的code:

<td>
    <span>Sex:&nbsp;</span>
</td>
<td>
    <span id="Sex_PDLabel" runat=server></span>
</td>

我怎么可以叫我的code这个返回值?
我想获得相应价值的任何变量。所以要尽量写code是这样的:

how i can call this return value in my code? i want to get corresponding value to any variable. so try to write code something like this:

 ScriptManager.RegisterStartupScript(DirectCast(HttpContext.Current.Handler, Page), GetType(Page), "GetSEx", "GetSex()", True)
 Dim SexVAl = Sex_PDLabel.InnerText

但我始终sexVal空越来越不string.i知道为什么吗?我的code中的问题是什么?

but my sexVal Always getting empty string.i dont know why? what is the problem with my code?

任何帮助是非常appriciable ..

any help is very appriciable..

推荐答案

使用此。

ASPX:
创建一个隐藏字段存储的值。

aspx: Create a hidden field to store the value.

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

JavaScript的code:

javascript code:

function GetSex()
{
    var sex = EIDAWebComponent.GetSex();
     alert(sex);
    if(sex == 'M')
        document.getElementById("txtHidden").value=  "Male";
    else if(sex == 'F')
        document.getElementById("txtHidden").value =  "Female";
    else if(sex == 'X')
        document.getElementById("txtHidden").value =  "Unknown";
    else
        document.getElementById("txtHidden").value =  "none";
}

从ASP.NET code呼叫:

Call from ASP.NET code:

ScriptManager.RegisterStartupScript((Page)(HttpContext.Current.Handler), 
                  typeof(Page), "GetSex", "GetSex();", true);

String value = txtHidden.Value;

这篇关于调用Java脚本返回值在asp.net code页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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