locked
Making a button visible is giving script error RRS feed

  • Question

  • User809760674 posted

    I have a gridview and when I select a row in the gridview the detailsview containing the data of that row opens. I want to show the submit button only when there is entry date in my table but I am getting script eror while doing so 

     protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
    DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
    BindDetailsView();
    Button1.Visible = true;
    Button1.Text = "Edit";
    con.Open();
    string fin_dt = "select vendor_creation_req.ucs_entry_dt from vendor_creation_req where req_no='" + GridView1.SelectedValue + "'";
    OleDbCommand cmd = new OleDbCommand(fin_dt, con);
    OleDbDataReader dr = cmd.ExecuteReader();
    dr.Read();
    if (dr.HasRows && dr["ucs_entry_dt"] == DBNull.Value)
    {
    submit.Visible = false;
    }
    else if (dr.HasRows && dr["ucs_entry_dt"] != DBNull.Value)
    {
    submit.Visible = true;
    }
    dr.Close();
    con.Close();
    BindGrid();
    GridView1.DataBind();
    }

    Saturday, June 15, 2019 7:14 AM

All replies

  • User753101303 posted

    Hi,

    laxmikathuria

    I am getting script error

    Always just tell which error you have and on which line it happens rather than forcing us to first guess which error you SEE. I see no obvious error but many possible problems depending on things you don't show.

    For now my understanding is that you have a JavaScript error (even though you show C# code ?) when the button is not visible. It is likely because you assume the button always exists while when the Visible property is false, no HTML at all is rendered for this control.

    Sunday, June 16, 2019 1:07 PM
  • User288213138 posted

    Hi laxmikathuria,

    According to the code you gave, I can't reproduce your problem.

    Please post your error message and aspx code.

    You can also debug your program to find problems.

    Best regards,

    Sam

    Monday, June 17, 2019 9:59 AM