Open Modal Code Behind

1

I have this modal and need to open it in the code-behind. I'm trying to JavaScript but it's not working, follow the code:

  $(document).ready(function () {
    //seleciona os elementos a com atributo name="modal"
    $('a[name=modal_servico]').click(function (e) {
        //cancela o comportamento padrão do link
        e.preventDefault();

        //armazena o atributo href do link
        var id_servico = $(this).attr('href');

        //armazena a largura e a altura da tela
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Define largura e altura do div#mask iguais ás dimensões da tela
        $('#mask_servico').css({ 'width': maskWidth, 'height': maskHeight });

        //efeito de transição
        $('#mask_servico').fadeIn(400);
        $('#mask_servico').fadeTo("slow", 0.8);

        //armazena a largura e a altura da janela
        var winH = $(window).height();
        var winW = $(window).width();
        //centraliza na tela a janela popup
        $(id_servico).css('top', winH / 2 - $(id_servico).height() / 2);
        $(id_servico).css('left', winW / 2 - $(id_servico).width() / 2);
        //efeito de transição
        $(id_servico).fadeIn(2000);
    });

    //se o botãoo fechar for clicado
    $('.window_servico .close_servico').click(function (e) {
        //cancela o comportamento padrão do link
        e.preventDefault();
        $('#mask, .window_servico').hide();
    });

    //se div#mask for clicado
    $('#mask').click(function () {
        $(this).hide();
        $('.window_servico').hide();
    });
});

    <div id="posicao_servico">
    <div id="boxes_servico">
        <div id="dialog_servico" class="window_servico">
            <div class="servico_box">
                <!-- Botão para fechar a janela tem class="close" -->
                <a href="#" class="close_servico" runat="server">
                    <asp:Image ID="Image8" runat="server" ImageUrl="~/images/icon/close-icon.png" />
                </a>
                <br />
                <asp:UpdatePanel ID="UpdatePanel4" runat="server">
                    <ContentTemplate>
                        <h3 class="servico_h3">Cadastrar Serviço</h3>
                        <br />
                        <asp:Label ID="Label10" runat="server" Text="Planos"></asp:Label>
                        <asp:DropDownList ID="cbPlanosServicos" runat="server" DataSourceID="SqlCadastra_servicos" DataTextField="descricao" DataValueField="id" AutoPostBack="True" OnSelectedIndexChanged="cbPlanosServicos_SelectedIndexChanged"></asp:DropDownList>
                        <asp:SqlDataSource ID="SqlCadastra_servicos" runat="server" SelectCommand="select descricao,id from dbo.servicos order by descricao asc" OnInit="SqlCadastra_servicos_Init" OnLoad="SqlCadastra_servicos_Load"></asp:SqlDataSource>
                        <br />
                        <asp:Label ID="Label14" runat="server" Text="Tipo de Plano"></asp:Label><br />
                        <asp:TextBox ID="txtTipodePlano" runat="server"></asp:TextBox>
                        <br />
                        <asp:Label ID="Label15" runat="server" Text="Data Inicio" ></asp:Label><br />
                        <asp:TextBox ID="txtDataInicio" runat="server" onBlur="limparDataInvalida(this);"></asp:TextBox>
                        <br />
                        <br />
                        <asp:Label ID="Label16" runat="server" Text="Data Fim" ></asp:Label>
                        <asp:Label ID="Label19" runat="server" Text="Vencimento"></asp:Label><br />
                        <asp:TextBox ID="txtDataFim" runat="server" onBlur="limparDataInvalida(this);"></asp:TextBox>
                        <asp:TextBox ID="txtDiaVencimento" runat="server" onChange='return SomenteNumero(event)'></asp:TextBox>
                        <asp:Label ID="Label18" runat="server" Text="Tolerância"></asp:Label><br />
                        <asp:TextBox ID="txtToleranca" runat="server"></asp:TextBox>
                        <br />
                        <br />
                        <br />
                        <asp:Label ID="Label17" runat="server" Text="Valor"></asp:Label><br />
                        <asp:TextBox ID="txtValorServico" runat="server"></asp:TextBox>

                    </ContentTemplate>
                </asp:UpdatePanel>
                <div class="proporcao">
                    <asp:CheckBox ID="checkPorp" runat="server" />
                    <asp:Label ID="Label20" runat="server" Text="Valor proporcional  R$"></asp:Label>
                    <asp:Label ID="lbValorPor" runat="server" Text=""></asp:Label><br />
                </div>
                <%--  <asp:UpdatePanel ID="UpdatePanel5" runat="server">
            <ContentTemplate>--%>
                <br />
                <div class="grid-11">
                    <asp:Button ID="btnGravarServico" runat="server" ForeColor="White" Text="Gravar" OnClick="btnGravarServico_Click" />
                </div>
                <br />
                <%--  </ContentTemplate>
        </asp:UpdatePanel>--%>
            </div>
        </div>
        <asp:TextBox ID="txtidReceita" runat="server" Visible="true"></asp:TextBox>
        <br />
        <asp:TextBox ID="txtIdServico" runat="server" Visible="false"></asp:TextBox>
        <br />

    </div>
</div>

And this is where I click and call (works great)

    <a href="#dialog_servico" name="modal_servico" class="linkmodal" runat="server" id="modalExercutar_servico">Cadastrar Serviço</a>

But I also need to open it in the code behind, so I tried:

function openServicos() {
    $('#dialog_servico').modal('show');
}

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myModal", "$(function() {openServicos();});", true);

But it does not open correctly, I tried the other ids, to see if it was getting wrong, only it does not, or it does not open correctly, or the screen goes dark. I use this code to open other modes, but this one that is different does not open. I do not know if there is another way to open it.

    
asked by anonymous 14.08.2017 / 17:38

0 answers