JavaScript函数成功,但未调用代码隐藏

JavaScript函数成功,但未调用代码隐藏,javascript,c#,jquery,asp.net,twitter-bootstrap,Javascript,C#,Jquery,Asp.net,Twitter Bootstrap,我的ASP站点中的代码隐藏和JavaScript一起工作时遇到问题 我得到了我公司活动的概述,当你点击“详细信息”按钮时,它应该进入数据库,收集有关该特定活动的所有可用数据,然后在引导模式窗口中显示 唯一的问题是,当前唯一发生的事情是显示模式窗口,而不显示其他内容。后面的代码甚至没有被调用 以下是我的JavaScript: function GetFullActivityDescription(id) { var onSuccess = function () { $('

我的ASP站点中的代码隐藏和JavaScript一起工作时遇到问题

我得到了我公司活动的概述,当你点击“详细信息”按钮时,它应该进入数据库,收集有关该特定活动的所有可用数据,然后在引导模式窗口中显示

唯一的问题是,当前唯一发生的事情是显示模式窗口,而不显示其他内容。后面的代码甚至没有被调用

以下是我的JavaScript:

function GetFullActivityDescription(id) {
    var onSuccess = function () {
        $('#full-activity-description-modal').modal('show');
    }
    var onFailed = function () { }
    var UserContext = this;
    PageMethods.GetFullActivityDescription(id, onSuccess, onFailed, UserContext);
}
这是C#:

[WebMethod]
公共静态无效GetFullActivityDescription(Int32 id)
{
mHeader.InnerHtml=“测试”;
mBody.InnerHtml=id+“”;
}
我必须进入运行全局元素的分部类,并将其默认声明更改为静态声明,以便可以从C#操作元素:

//
///模态_头控制。
/// 
/// 
///自动生成的字段。
///将字段声明从设计器文件修改为代码隐藏文件。
/// 
public static System.Web.UI.HtmlControls.HtmlGenericControl modal_头;
/// 
///模态控制。
/// 
/// 
///自动生成的字段。
///将字段声明从设计器文件修改为代码隐藏文件。
/// 
public static System.Web.UI.HtmlControls.HtmlGenericControl modal_body;
以下是HTML:

<div id="full-activity-description-modal" class="modal fade" role="dialog">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header" runat="server" id="modal_header"></div>
            <div class="modal-body" runat="server" id="modal_body"></div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger btn-bg" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

接近
我需要做的有点复杂,因为我需要ASP而不是提交表单。否则它就没有意义了,因为模式窗口将被重置

现在,“拼图”的最后一块是描述按钮的生成方式:

html.Append("<td>");
html.Append("<a onclick=\"GetFullActivityDescription(" + id + ");\" class=\"btn\" style=\"background-color: #F3F3F3; color: #000000; font-size: 18px;\">");
html.Append("<span class=\"ion ion-clipboard\"></span>");
html.Append("</a>");
html.Append("</td>");
html.Append("</tr>");
html.Append(“”);
html.Append(“

那么,我想说明一个问题:为什么调用了我的JavaScript函数,却没有调用我的C#代码

编辑1

这是通过Site.Master添加的ScriptManager,此页面从中继承

<asp:ScriptManager runat="server" EnablePageMethods="true" EnablePartialRendering="true">
    <Scripts>
        <%--To learn more about bundling scripts in ScriptManager see http://go.microsoft.com/fwlink/?LinkID=301884 --%>
        <%--Framework Scripts--%>
        <asp:ScriptReference Name="MsAjaxBundle" />
        <asp:ScriptReference Name="bootstrap" />
        <asp:ScriptReference Name="respond" />
        <asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
        <asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
        <asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
        <asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
        <asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
        <asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
        <asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
        <asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
        <asp:ScriptReference Name="WebFormsBundle" />
        <%--Site Scripts--%>
    </Scripts>
</asp:ScriptManager>

我认为您只需要更改Javascript和代码。从您的代码中,我可以看出您正在使用JQuery,我也使用JQuery来处理模式

JavaScript

function GetFullActivityDescription(id) {
    $.get("PageName.aspx/MethodName",{ id: id }, function(data) {

        $('#full-activity-description-modal').modal('show');

    });
}
C#

[WebMethod]
公共静态无效GetFullActivityDescription(Int32 id)
{
mHeader.InnerHtml=“测试”;
mBody.InnerHtml=id+“”;
}

在您的C#代码中,尝试使用
ScriptManager.RegisterStartupScript(您的控件,this.getType(),“theNameOfYourJSFunction”,“theNameOfYourJSFunction(+valueToPass+),True)
。您还需要将C代码放入绑定到控件的某种事件中,以便调用C代码。目前,服务器端没有任何东西在调用您编写的C代码。例如,在
页面加载
函数中调用
GetFullActivityDescription

您有脚本管理吗r添加到您的aspx页面?是的,该页面从站点继承。Master您检查过吗?@Zippy如果我删除该行,则
将停止工作。webopt在其中。请尝试检查响应,例如:
var result=PageMethods.GetFullActivityDescription(id,函数(响应){alert(响应)});
如何调用“响应”"在静态方法中?这是不可能的。是的,以前忽略了这一点,抱歉,但是javascript可以启动mothod Now吗?不,它根本不运行,因为我无法使用您当前的解决方案编译它。我再次修改了它…Now怎么样?不,它不做我想做的事情,抱歉。如果我执行了您建议的调用,那么javascript将在加载页面上调用这不是我真正想要的。还有
PageMethods.GetFullActivityDescription(JSON.stringify(arr)、onSuccess()、onFailed()、UserContext);
这一行是调用我的服务器端方法的。
<asp:ScriptManager runat="server" EnablePageMethods="true" EnablePartialRendering="true">
    <Scripts>
        <%--To learn more about bundling scripts in ScriptManager see http://go.microsoft.com/fwlink/?LinkID=301884 --%>
        <%--Framework Scripts--%>
        <asp:ScriptReference Name="MsAjaxBundle" />
        <asp:ScriptReference Name="bootstrap" />
        <asp:ScriptReference Name="respond" />
        <asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
        <asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
        <asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
        <asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
        <asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
        <asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
        <asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
        <asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
        <asp:ScriptReference Name="WebFormsBundle" />
        <%--Site Scripts--%>
    </Scripts>
</asp:ScriptManager>
function GetFullActivityDescription(id) {
    $.get("PageName.aspx/MethodName",{ id: id }, function(data) {

        $('#full-activity-description-modal').modal('show');

    });
}
[WebMethod]
public static void GetFullActivityDescription(Int32 id)
{
    mHeader.InnerHtml = "<h1>Test</h1>";
    mBody.InnerHtml = id + "";
}