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.

3
  • What does the ABC function do? programmers.stackexchange.com/questions/171203/… Commented Mar 7, 2014 at 4: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. Commented Mar 7, 2014 at 4:45
  • How can I read the query parameter from client? Commented Mar 7, 2014 at 5:49

2 Answers 2

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!

Sign up to request clarification or add additional context in comments.

Comments

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?

1 Comment

Why is this dangerous?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.