call request.querystring inside javascript function

asp.net, c#, javascript

Solution

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>

Problem

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

Original source

Related problems