0
<%@ Page Language="C#" AutoEventWireup="true" %>
    <%
        string paramString = Request.QueryString["query"];
        if (null != paramString)
        {
            if (paramString.ToLower() == "ValueIsRight".ToLower())
            {
                //Here I want to invoke ABC function below defined in my asp page
            }
        }
    %>

 <script type="text/javascript">
        function ABC {
            }
</script>

I am very new to ASPX and want to know if there is anyway to call this function? I tried using the call keyword but it doesn't come up in my IDE.

Adam Zuckerman
  • 1,633
  • 1
  • 14
  • 20
Frank Q.
  • 6,001
  • 11
  • 47
  • 62
  • What does the ABC function do? http://programmers.stackexchange.com/questions/171203/what-are-the-difference-between-server-side-and-client-side-programming – user13500 Mar 07 '14 at 04:23
  • why are you involving c#(server side) this can be done solely from javascript. just ready the querystring and call the function from client side only. – Ratna Mar 07 '14 at 04:45
  • How can I read the query parameter from client? – Frank Q. Mar 07 '14 at 05:49

2 Answers2

1

So as far as I can recall, you can't really do that. The c# runs on the server before shipping off the html for the client's request, so running that javascript function would require the server to have its own javascript engine running, which ASP does not. What you can do though, is a flag variable to the javascript, so whne the client loads, it can run differently based on the flag you pass in. For example

<script type="text/javascript">ABC(<%: someFlag.toString() %>)</script>

will pass that variable to your script to run!

Brent Echols
  • 590
  • 2
  • 9
0

Well the most basic and dangerous way would be

    <script type="text/javascript">
    function ABC {
        }
     </script>
<%@ Page Language="C#" AutoEventWireup="true" %>
<%
    string paramString = Request.QueryString["query"];
    if (null != paramString)
    {
        if (paramString.ToLower() == "ValueIsRight".ToLower())
        {
             Response.Write("<script>");
             Response.Write("ABC();");
             Response.Write("</script>");
            //Here I want to invoke ABC function below defined in my asp page

            //dont use this method
        }
    }
%>

/////////end///////////// NOTE: javascript Function definition is at the starting.

Please use ScriptManager.RegisterStartupScript

To know in greater detail visit http://www.dotnetcurry.com/showarticle.aspx?ID=200

To get querystring on client

  function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
    results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));

}

source-->How can I get query string values in JavaScript?

Community
  • 1
  • 1
Ratna
  • 2,289
  • 3
  • 26
  • 50