locked
accessing asp table control in static web method RRS feed

  • Question

  • User-173333858 posted

    I am changing the opacity to fade out an asp table in code behind on page load. On a textbox text entered event, I want to change it back to being enabled and fully visible. I tried using jquery, but unable to do so. I then tried to call a web method in code behind from the jquery textbox event  function to change the opacity and enabling it. But how do I access the asp table in this static web method.? 

    Method 1) This is the jquery code that did not work:
    function EnableDisableNext1() { if ($("#<%=StrNotCommentsBox.ClientID%>").val().length > 0) {        $('#PharmSubmitTbl2').css({ opacity : '0.9', filter: 'alpha(opacity=90)' }); ///// This is the asp table     alert("111"); } Method 2) Then I tried calling a static web method : function EnableDisableNext1() { if ($("#<%=StrNotCommentsBox.ClientID%>").val().length > 0) { $.ajax({ type: "POST", url: "PharmAudit_Form.aspx/EnableRightPane", contentType: 'application/json; charset=utf-8', dataType: 'json', async: true, error: function (XMLHttpRequest, textStatus, errorThrown) { //alert(textStatus); //alert(errorThrown); window.location.href = "Logout.aspx"; }, success: function () { var parsedResult = result.d; if (parsedResult) { if (parsedResult.error_code == "0") // no error { alert("#1"); window.location.href = 'LandingForm.aspx'; this.display = none; } else if (parsedResult.error_code == "2") { alert("#2"); window.location.href = "Logout.aspx?ErrorValue=" + "2"; } } } }); } In code behind: [WebMethod(EnableSession = true)] public static void EnableRightPane() { Table t1 = System.Web.HttpContext.Current.Session["PharmTbl2"] as Table; t1.Style.Add("opacity", "1"); t1.Enabled = true; } where Session["PharmTbl2"] = PharmSubmitTbl1 as Table; Let me know where this is failing. Thanks!
    Friday, August 28, 2020 9:27 PM

All replies

  • User1535942433 posted

    Hi RDesh,

    Accroding to your description and codes,as far as I think,your jquery is wrong and the function doesn't work.You could press F12 and check if there are errors.

    More details,you could refer to below codes:

       <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
        <script>
             $(function () {
    $("#Button1").click(){
    if ($("#<%=TextBox1.ClientID%>").val().length > 0) {
    $('#table1').css({ opacity: '0.9', filter: 'alpha(opacity=90)' })
    }
    }
    }) </script> <div> <table id="table1"> <tr> <td> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </td> <td>2</td> <td>3</td> </tr> <tr> <td>4</td> <td>5</td> <td>6</td> </tr> <tr> <td>7</td> <td>8</td> <td>9</td> </tr> </table> </div> <asp:Button ID="Button1" runat="server" Text="Button" />

    But how do I access the asp table in this static web method.? 

    You couldn't access control in the web method.

    Besides,I suggest you post your codes with formatted.

    Best regards,

    Yijing Sun

    Monday, August 31, 2020 7:44 AM
  • User-173333858 posted

    Hi Yijing ,

    Thank you for your reply. There was a list of jquery updates that needed to be made, giving a lot of errors when I pressed F12. I solved them all, but still the opacity does not change on this. I have an alert after this statement, which executes. But the opacity remains the same. I think I am also changing the opacity in code behind, that is causing some conflict with the DOM?

    Monday, August 31, 2020 1:21 PM
  • User753101303 posted

    Hi,

    You could also use https://developers.google.com/web/tools/chrome-devtools/css and inspect the CSS for this element to see if an opacity is really supposed to be applied. If not might be a logic flaw in your code.

    My understanding is that you want to show a table with an opacity value and then turn it back to opaque as soon as a character is entered inside a textbox. The first step might be to show what you are doing to have an opactiy value when this table is first shown.

    If using IE make sure it is not using an old legacy mode that wouldn't support your approach.

    Edit: rather to have fun but if using a modern browser a possible option could be something such as:

    <input type="text" required>
    <table>
    <tr><th>A</th></tr>
    <tr><td>line 1</td></tr>
    </table>

    and :

    input:invalid + table {opacity: 0.9;}

    The input text field is required and if not valid the table element following this input field does have a 0.9 opacity. As soon as you start entering a value, the element is not invalid anymore and the 0.9 opacity doesn't apply.

    Monday, August 31, 2020 7:41 PM