Click here to Skip to main content
15,906,567 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have the javascript code like this
JavaScript
<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);
        }

and i have a function like GetDate in my .cs page
C#
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;
        }
    }

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

[Edit]Code block added[/Edit]
Posted
Updated 31-Oct-12 2:36am
v2
Comments
Sergey Alexandrovich Kryukov 1-Nov-12 9:52am    
First, please don't re-post. It cannot help you, but can cause down-votes and abuse reports.
And the question makes no sense. You need to understand how Web works, what happens on client side and server side... it looks like you have not clue yet. Not a problem -- read on this topic; and you will see.
--SA

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[^]
 
Share this answer
 
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/[^]
 
Share this answer
 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900