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?
asked Apr 18, 2013 at 15:11
Matthew
4,64722 gold badges73 silver badges95 bronze badges
2 Answers 2
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
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);
answered Apr 18, 2013 at 15:28
Abbas
6,8944 gold badges38 silver badges49 bronze badges
Comments
default