0

Tried using $('#btnEnter').prop('disabled', true); but my button will not be disabled. Also when I click the back button the page will crash.

jquery

<script>
    function gray() {
        $('#btnEnter').prop('disabled', true); 
    }
</script>

Child page that has button to be disabled

 <asp:Button ID="btnEnter" CssClass="btn btn-light btn-md btn-block" runat="server" Text="Enter Value" OnClick="btnEnter_Click"/>

codebehind child page

public partial class Institution1Submit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        checkConnection();
    }

    //check if connected before going submit page
    public async void checkConnection()
    {

      ScriptManager.RegisterStartupScript(this, this.GetType(), "n", "gray();", true);

    }}

Back button

 protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("../Nodes.aspx");
    }
user3803747
  • 292
  • 2
  • 5
  • 14
  • is the button id rendered as `btnEnter` or is it replaced with a unique client id? If you are using .net 4.8, you could use the static client id mode: https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.control.clientidmode?view=netframework-4.8 – Pete Jun 18 '19 at 14:50
  • From jQuery point of view your code looks fine. There are few possible scenarios which may cause your problem. First of all, you have to ensure, that your jquery script is included before using. Second, you have to try wrap you gray() function into document.ready function, to ensure, that you are manipulating DOM after it was fully loaded. – dganenco Jun 18 '19 at 14:51
  • It's not the jquery. After the page is loaded, what is the ID? I'll bet it's not `btnEnter` – shadow2020 Jun 18 '19 at 18:17

0 Answers0