OnClientClick不起作用

时间:2015-05-22 19:49:52

标签: javascript c#

我有这个按钮:

<asp:Button runat="server" ID="botao" OnClientClick="submit();" OnClick="submeter" Text="Pedir Revisão" />

和这个JavaScript函数:

function submit() {
    alert("entrei");
    //tabelaAutores
    var tabela = document.getElementById("tabelaAutores");
    var tableAux = document.getElementById('<%=tabelaAutoresAux.ClientID %>');
    var x = tabela.rows.length;
    for (i = 1; i < x; i++) {
        tableAux.innerText += tabela.rows[i].cells[0].innerText + "/" + tabela.rows[i].cells[1].innerText + "|";
    }
    alert(tableAux.innerText);
    return false;
}

和这个C#函数:

protected void submeter(object sender, EventArgs e)
{
    Debug.WriteLine("aqui----");
    Debug.Write(tabelaAutoresAux.InnerText);
    int id = int.Parse(Request.QueryString["id"]);
    //adicionar autores
    String[] aC = tabelaAutoresAux.InnerText.Split('|');
    for (int i = 0; i < aC.Length - 1; i++)
    {
        String[] aC2 = aC[i].Split('/');
        DataTable pessoa = DBConFactory.getInstance().getPessoaByEmail(aC2[1]);
        if (pessoa.Rows.Count != 0)
        {
            bool x = DBConFactory.getInstance().add(int.Parse(pessoa.Rows[0]["nOrdem"].ToString()), id); 
        }
    }
}

代码输入c#函数,但不是JavaScript代码。

这是整个代码。

<%@ Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="AdicionarRevisor.aspx.cs" Inherits="CasosClinicos.Admin.AdicionarRevisor" %>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
    <script>
        var PopupImageContainer = new Image();
        var PopupImageCaption = new String();
        var PopupImageSRC = new String();

        function PopImage(imagesrc, caption) {
            if (length.imagesrc < 1) { return; }
            var loadDelay = PopupImageSRC.length ? 1 : 750;
            PopupImageSRC = imagesrc;
            PopupImageCaption = caption ? caption : 'Image';
            PopupImageContainer.src = PopupImageSRC;
            setTimeout("PopupImageDisplay()", loadDelay);
        }

        function PopupImageDisplay() {
            var iw = $(window).width() - 50;
            var ih = $(window).height() - 50;
            var ww = $(window).width();
            var hh = $(window).height();
            var properties = 'height=' + hh + ',width=' + ww + ',resizable=yes,location=center';
            var picture = window.open('', '', properties);
            picture.document.writeln('<html><head>');
            picture.document.writeln('<script language="JavaScript"> function CloseMe() { self.close(); } <' + '/script>');
            picture.document.write('<' + '/head><body onBlur="CloseMe()"><center>');
            picture.document.write('<img id="' + PopupImageSRC + '" src="' + PopupImageSRC + '" width="' + iw + '" height="' + ih + '" border="0">');
            picture.document.write('<p>' + PopupImageCaption + '<' + '/p>');
            picture.document.writeln('<' + '/center><' + '/body><' + '/html>');
        }
    </script>
    <script>
        function addAutorB() {
            var select = document.getElementById('<%=listaAutores.ClientID %>').value;
            if (select.localeCompare("") == 0) {
                return;
            }
            else if (select.localeCompare("Adicionar Novo") == 0) {
                document.getElementById("camposAutor").style.display = "block";
                document.getElementById("initial").selected = true;
            }
            else {
                var x = select.split("(");
                document.getElementById("autores").value = x[0];
                document.getElementById("contato").value = x[1].split(")")[0];
                addAutor();
            }
            document.getElementById("initial").selected = true;
        }

        function addAutor() {
            var table = document.getElementById("tabelaAutores");
            var row = table.insertRow(1);
            var cell1 = row.insertCell(0);
            var cell2 = row.insertCell(1);
            var cell3 = row.insertCell(2);
            cell1.innerText = document.getElementById("autores").value;
            cell2.innerText = document.getElementById("contato").value;
            cell3.innerHTML = "<button type=\"button\" onclick=\"return deleteRow(this)\" class=\"btn btn-default\" aria-label=\"Left Align\"><span class=\"glyphicon glyphicon-remove\" aria-hidden=\"true\"></span></button>";
            document.getElementById("autores").value = "";
            document.getElementById("contato").value = "";
            document.getElementById("camposAutor").style.display = "none";
            return false;
        }
        function deleteRow(r) {
            var i = r.parentNode.parentNode.rowIndex;
            document.getElementById("tabelaAutores").deleteRow(i);
            return false;
        }
        function submit() {
            alert("entrei");
            //tabelaAutores
            var tabela = document.getElementById("tabelaAutores");
            var tableAux = document.getElementById('<%=tabelaAutoresAux.ClientID %>');
            var x = tabela.rows.length;
            for (i = 1; i < x; i++) {
                tableAux.innerText += tabela.rows[i].cells[0].innerText + "/" + tabela.rows[i].cells[1].innerText + "|";
            }
            alert(tableAux.innerText);
            return false;
        }
    </script>
    <br />
    <br />

    <div class="row">
        <div class="col-md-6">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><strong>Revisores</strong></h3>
                </div>
                <div class="panel-body">
                    <div class="form-group">
                        <label for="autores">Revisores</label>

                        <select runat="server" id="listaRevisores" onchange="addAutorB()">
                            <option id="initial"></option>
                        </select>
                        <br />
                        <label for="autores">Autores</label>

                        <select runat="server" id="listaAutores" onchange="addAutorB()">
                            <option id="initial1"></option>
                        </select>

                        <style>
                            table.fixed {
                                table-layout: fixed;
                            }

                                table.fixed td {
                                    overflow: hidden;
                                }
                        </style>

                        <div id="camposAutor" style="display: none;">
                            <input type="text" id="autores">
                            <input type="text" id="contato" />
                            <button type="button" onclick="return addAutor()" class="btn btn-default" aria-label="Left Align\"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
                        </div>


                        <table id="tabelaAutores" border="1" class="fixed">
                            <col width="255px" />
                            <col width="255px" />
                            <col width="90px" />
                            <tr>
                                <td><strong>Autor</strong></td>
                                <td><strong>Contato</strong></td>
                                <td></td>
                            </tr>
                        </table>
                        <br />
                    </div>
                    <div id="autoresAux" runat="server" style="display: none;">
                        <textarea runat="server" id="tabelaAutoresAux"></textarea>
                    </div>
                    <div>
                        <asp:Button runat="server" ID="botao" OnClientClick="submit();" OnClick="submeter" Text="Pedir Revisão" />
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <div class="panel panel-default" style="position: fixed; overflow: auto; height: 85%">
                <div class="panel-heading">
                    <h3 class="panel-title"><strong>Caso</strong></h3>
                </div>
                <div class="panel-body">
                    <div style="overflow: auto; padding: 5px;">
                        <div class="form-group">
                            <label runat="server">Titulo: </label>
                            <p runat="server" id="text_titulo"></p>
                            <label runat="server">Autores: </label>
                            <p runat="server" id="text_autores"></p>
                            <label runat="server">Intituição: </label>
                            <p runat="server" id="text_inst"></p>
                            <label>Resumo: </label>
                            <pre runat="server" id="text_resumo"></pre>
                            <div id="conteudo">
                                <p runat="server" id="text_conteudo"></p>
                            </div>
                            <label>Imagens: </label>
                            <p runat="server" id="text_img"></p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</asp:Content>

我尝试过各种各样的事情......用<button onclick="submit">botao</button>代替按钮,它不起作用。

2 个答案:

答案 0 :(得分:0)

尝试将submit()重命名为submit1()的其他名称...因为submit()是用于通过jquery提交页面的函数。可能会导致冲突。所以总是尽量避免使用那种关键字或功能名称

答案 1 :(得分:0)

我认为您需要在C#中从服务器端调用JavaScript函数

尝试这个让我知道它是否有效

protected void btne_Click(object sender, EventArgs e)
{
    ScriptManager.RegisterStartupScript(this, GetType(), "myFunction", "myFunction();", true);            
}