简体   繁体   English

如何将字符串参数传递给javascript函数

[英]How to pass String Argument to javascript function

This is my front-end: 这是我的前端:

ImageButton Details = (ImageButton)e.Row.FindControl("iBtnDetails");//take lable id
                String strApplication1 = Details.CommandArgument.ToString();

                e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';";
                e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
                e.Row.Attributes.Add("onClick", "SelectRow()");

This is my back-end: 这是我的后端:

<script type="text/javascript">
                function SelectRow() {

                    var strApplication1 = '<%=strApplication1%>'

                    if (strApplication1 == "IT Application Request")
                    {

                         window.open('http://.aspx', '_blank');
                    }

                    else if (strApplication1 == "IT Account Request")
                    {
                         window.open('http://.aspx', '_blank');

                    }
                    else if (strApplication1 == "Change Control Management")
                    {
                         window.open('http://.aspx', '_blank');
    }
                    else if (strApplication1 == "Backup & Restore")
                    {
                        window.open('http://.aspx', '_blank');
                    }
                }

</script>

I want to pass String Argument to javascript function, but I got error that strApplication1 doesn't exist in the current context. 我想将String Argument传递给javascript函数,但出现错误,指出在当前上下文中strApplication1不存在。

You need to make strApplication1 a public property on your page class. 您需要将strApplication1页面类的公共属性。 Currently, it is just an internal variable. 当前,它只是一个内部变量。

Something like: 就像是:

public partial class YourPage : System.Web.UI.Page
{
    public string strApplication1 {get; set;}

    protected void Page_Load(object sender, EventArgs e)
    {
         //Your page logic          
    }

    //Looks like you set the variable in an onDatabound or similar.
    //So use this where you currently set the variable
    strApplication1 = Details.CommandArgument.ToString();

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将字符串变量作为参数传递给javascript函数? - How to pass a string variable as an argument to a javascript function? 如何从PHP端传递JavaScript函数中的数组字符串作为参数? - how to pass array string in JavaScript function from PHP end as a argument? 如何在JavaScript函数中将“ this”作为参数传递? - How to pass `this` as an argument in javascript function? JavaScript:如何将字符串参数传递给函数以用于按该字符串参数的值对对象数组进行排序? - JavaScript: How do I pass a string argument to a function to use to sort an array of objects by the value of that string argument? 如何在Javascript接口中将Javascript函数作为参数传递? - How to pass a Javascript function as an argument in Javascript Interface? 如何将函数作为参数传递给Javascript中的自定义函数 - How to pass a function as an argument to a custom function in Javascript 如何将字符串参数传递给 javascript 方法 - How to pass string argument to javascript method 在javascript中传递一个函数作为参数 - pass a function as argument in javascript 如何将第二个参数传递给javascript函数 - How to pass a second argument to a javascript function 如何在javascript中将值/参数传递给map函数 - How to pass value/argument to the map function in javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM