Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing Eval from ASPX to Javascript function as Parameter

Tags:

<a id="lblShowTimings"
     runat="server"
     title='<%# Eval("SHOW_Name") %>'
     onclick='PopulateTicketDiv(<%#Eval("SHOW_ID") %>)'>  <-- this is the problem
  %#Eval("SHOW_Time") %>
</a>

Can Eval be passed as an argument to a javascript function? If so whats the syntax?

like image 333
naveen Avatar asked Oct 30 '08 11:10

naveen


People also ask

Why we should not use eval in JavaScript?

eval() is a dangerous function, which executes the code it's passed with the privileges of the caller. If you run eval() with a string that could be affected by a malicious party, you may end up running malicious code on the user's machine with the permissions of your webpage / extension.

What is alternative for eval function in JavaScript?

An alternative to eval is Function() . Just like eval() , Function() takes some expression as a string for execution, except, rather than outputting the result directly, it returns an anonymous function to you that you can call. `Function() is a faster and more secure alternative to eval().

What is $$ eval?

page.$$eval(selector, pageFunction[, ...args])This method runs Array. from(document. querySelectorAll(selector)) within the page and passes it as the first argument to pageFunction . If pageFunction returns a Promise, then page. $$eval would wait for the promise to resolve and return its value.


1 Answers

Yes. What you want to do is this, though:

onclick='<%# "PopulateTicketDiv(" +Eval("SHOW_ID") + " );" %>'
like image 154
tvanfosson Avatar answered Oct 28 '22 00:10

tvanfosson