Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

call request.querystring inside javascript function

how to call Request.QueryString inside javascript function and i am using asp.net and C#

var str=<%=Request.quesryString("val")%>

but it is giving me error

like image 323
navya Avatar asked Jun 10 '26 10:06

navya


1 Answers

If this javascript code is inline in your webform the correct way is to use a javascript serializer:

<script type="text/javascript">
    var str = <%= new JavaScriptSerializer().Serialize(Request.QueryString["val"]) %>;
    alert(str);
</script>

Never do the following, it's completely unsafe and your site vulnerable to XSS injection attacks:

<script type="text/javascript">
    var str = '<%= Request.QueryString["val"] %>';
    alert(str);
</script>
like image 56
Darin Dimitrov Avatar answered Jun 12 '26 22:06

Darin Dimitrov