1

I have the following line of code in C#:

Page.ClientScript.RegisterStartupScript(Page.GetType(), null, "window.open('http://localhost:4000/Transaction_Number.aspx?num=<%=trans_number%>', '_newtab')", true);

Now, trans_number is a variable in my C# code-behind. My problem is that when I process the query string (num variable), the result is always:

<%trans_number%>

instead of the contents of that variable. How can I solve this?

0

2 Answers 2

8

I think, you can resolve this pretty easily... Maybe:

Page.ClientScript.RegisterStartupScript(Page.GetType(), null, "window.open('http://localhost:4000/Transaction_Number.aspx?num=" + trans_number + "', '_newtab')", true);
Sign up to request clarification or add additional context in comments.

Comments

2

You have a string that concatenates with a variable and is in turn embedded within another string. Issues like this tend to go away when you use intermediate variables and String.Format method:

string url = String.Format(@"http://localhost:4000/Transaction_Number.aspx?num={0}", trans_number);
string js = String.Format("window.open('{0}', '_newtab')", url);

Page.ClientScript.RegisterStartupScript(Page.GetType(), null, js, true);

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.