1

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.

1 Answer 1

2

You need to make strApplication1 a public property on your page class. 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();

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.