没有被调用的功能 [英] function is not being called

查看:88
本文介绍了没有被调用的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的javascript代码

i have the javascript code like this

<script type="text/javascript">
        var classid , examid;
        function GetData()
        {
    debugger
            classid = document.getElementById("<%=ddlbatch.ClientID%>").value;
            examid  = 0;
            // I need to read returned data table below
           GetData(classid,examid);
            //WebService.GetData(classid,examid);
        }


我的.cs页面中有一个类似GetDate的函数


and i have a function like GetDate in my .cs page

public DataTable GetData(int classid, int examid)
    {
        
        DataTable dt = new DataTable();
       
        cn = WebConfigurationManager.ConnectionStrings["ExpertsSchoolConnectionString"].ConnectionString;
        using (SqlConnection con = new SqlConnection(cn))
        {
            SqlCommand com = new SqlCommand();
            //  com.Connection = con;
            com.CommandType = CommandType.StoredProcedure;
            com.CommandText = "ES_SUBJECT_EXAM";
            SqlParameter classid1 = new SqlParameter("@classid", SqlDbType.Int);
             classid1.Value = classid ;
            com.Parameters.Add(classid1);

            SqlParameter examid1 = new SqlParameter("@examid", SqlDbType.Int);
            examid1.Value = examid ;
            com.Parameters.Add(examid1);
            try
            {
                con.Open();
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = com;
                da.Fill(dt);
            }
            catch (Exception ex)
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
                dt = null;
            }
            finally
            {
                con.Close();
            }
            return dt;
        }
    }


但是当我执行javascript代码时,该函数没有被调用,请问有没有错误?

添加了代码块[/编辑]


but when i executed the javascript code the function is not being called ,can any one please tell whether there is any error?

Code block added[/Edit]

推荐答案

您将无法执行此操作,必须使用通过webmethod进行的静态方法调用
看看这个
http://geektube.tv/video/fzA3L6C7wOU/Passing-Parameters- to-WebMethod-Using-JQuery-Ajax-API [ ^ ]
You will not be able to do that, You will have to use a static method call using webmethod
have a look at this
http://geektube.tv/video/fzA3L6C7wOU/Passing-Parameters-to-WebMethod-Using-JQuery-Ajax-API[^]


您不能直接通过客户端脚本(javascript)调用服务器端函数.
请通过此链接

从服务器端调用客户端JavaScript功能() [ ^ ]

http://tuvianblog .com/2011/06/10/how-to-call-serverside-function-from-client-side-javascript-in-asp-net/ [
You can''t call server side function from client script (javascript) directly the way you are calling.
Please go through this links

Call Client Side JavaScript function() from Server Side[^]

http://tuvianblog.com/2011/06/10/how-to-call-serverside-function-from-client-side-javascript-in-asp-net/[^]


您不能直接以调用方式从客户端脚本(javascript)调用服务器端函数.
Google的一些文章如何在asp.net中从客户端调用服务器端函数",您将找到正确的方法.
You cannot call serverside function from client script (javascript) directly the way you are calling.
Google some of the articles for "how to call serverside function from client side in asp.net" and you would find the proper way.


这篇关于没有被调用的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆