problem with asp.net and jquery

2

Good day, I have a small problem, I hope you can help me: I have a form in ASP.Net, where the user's data is loaded, these fields are disabled so that they can not be edited, but I have a button with which to enable them, the problem is that when clicking this it does not work ..

This is my button:

<asp:LinkButton runat="server" ID="empEdit" class="btn btn-primary" ClientIDMode="Static"><span class="glyphicon glyphicon-pencil" ></span> Editar</asp:LinkButton>

this my jquery code:

$('#empEdit').click(function () {
$('[id^=emp]').removeProp('disabled');
});

the id of the fields start with "emp", I put the static ids in asp so that they do not change when loading the page in the browser with ClientIDMode="Static" and even then it does not work ...

    
asked by david arellano 04.04.2017 в 19:03
source

3 answers

3

It's because the IDs generated by ASPnet WebForms have a nomenclature based on sections, if you have a masterpage for example the ID will be something like this: ctlSeccionDelMaster$IDdelComponente , to correctly hit the ID you are looking for, I recommend you do the following:

$("#<%=empEdit.ClientID %>").click(function () {
    $('[id^=emp]').removeProp('disabled');
});

Update 10 April 2017

I just played something similar to the environment you have and I hope it's what you have in mind:

<asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="activarBotones()">LinkButton</asp:LinkButton>
<asp:Button ID="Button1" runat="server" Text="Button" Enabled="false" />
<asp:TextBox ID="TextBox1" runat="server" Enabled="false"></asp:TextBox>

<script type="text/javascript">

    function activarBotones() {
        $('#<%=Button1.ClientID %>').prop("disabled", false);
        $('#<%=TextBox1.ClientID %>').prop("disabled", false);
    }

</script>

On the aspx page you're working with:

protected void Page_Load(object sender, EventArgs e)
{
    LinkButton1.Attributes.Add("onClick", "return false;");
}      
    
answered by 04.04.2017 в 19:29
0

This is a fragment of the form, a running input:

<input name="ctl00$ContentPlaceHolder1$empNombre" value="AUTO LINEAS AMERICA S.A DE C.V." id="empNombre" class="form-control" type="text" placeholder="Cliente Mostrador" disabled="disabled" pmbx_context="ACE58F01-58AE-42C0-8238-BDBDBFA24F8D">

add the id to the jquery code:

$("#<%=empEdit.ClientID %>").click(function () {
    $('[id^=emp]').prop('disabled', '');
});

although the button has ClientIDMode="Static"

  <asp:LinkButton runat="server" ID="empEdit" class="btn btn-primary" OnClientClick="return btn_disable" ClientIDMode="Static"><span class="glyphicon glyphicon-pencil" ></span> Editar</asp:LinkButton>
    
answered by 04.04.2017 в 20:38
0

If that button only serves to enable the inputs or textboxs, why do not you do that button with html you put an id and you load the function you already have

<button id="btnEnable" class="btn btn-primary">Editar</button>
//y el tu script lo dejas como esta
$('#btnEnable').click(function () {
   $('[id^=emp]').removeProp('disabled');
});
    
answered by 06.04.2017 в 23:42