Call a js function in C#

Posted on 2007-10-16
Last Modified: 2013-12-17
I am very new to c#.  I can figure most things out, but can't find documentation on how to do this.  Based on the scenerio below, how do I call a function in the project folder Common/CommonFunctions.js to fill the placeholder Summary2ndHolder with the return string, using a stored procedure to pass part of the parameters needed for the function and hard coding the rest of the parameters?

.aspx page with a placeholder:
<html xmlns="">
<head runat="server">
    <title>Summary Detail</title>
    <link href="Common/Standard.css" type="text/css" rel="stylesheet">
    <form id="form1" runat="server">
         <div id="paContent" class="headersmall">
            <div align="center">
                <asp:Literal ID="SummaryHolder" runat="server" />&nbsp;
                 <asp:Literal ID="Summary2ndHolder" runat="server" />

Code behind is C#:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Quality.Business;

namespace Quality.UI
    public partial class SummaryDetail : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
             // get summary detail data
            if (!Page.IsPostBack)
                using (Business.SummaryDetails summaryDetails = new SummaryDetails())
                    SummaryHolder.Text = summaryDetails.GetSummaryDetails(Agent_Code, GroupRatingYear_ID, Server.MapPath("xsl"));

function DoSomething(parm0, parm1, parm2, parm3, parm4, parm5, parm6, parm7, parm8)
//create the returnstring using passed parameters
     return returnstring;
Question by:cswebdev
    LVL 21

    Expert Comment

    You can store the data you might be getting from the stored proc into a javascript hidden variable and then call the js function passing the variable and other variables.

    Why cant you set the literal using C# code, why use javascript?

    Author Comment

    Our mandate is to keep functions in a seperate place and the project already has functions in CommonFunctions.js.  Stored procs are called from individual c# pages and I will have to create one for this stored proc to get the variables, which I can store and use.  I just need to know how to call the js function from within my c# codebehind page.  I hope I explained this correctly.
    LVL 21

    Accepted Solution

    >>  I just need to know how to call the js function from within my c# codebehind page.

    You will not be able to call a java script in the middle of your c# code execution. A javascript is a client side scripting language and will be executed only when the HTML generated by your C# code reaches a browser

    Author Comment

    Thank you.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This is an explanation of a simple data model to help parse a JSON feed
    Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now