locked
Making Edit Linkbutton invisble in repeater using Javascript function RRS feed

  • Question

  • User-1578974752 posted

    Hi

    I have  4 link buttons and few textboxes inside the repeater panel.When i click Edit link button i want to make the Edit Link button invisble and show the Update link button.Textbox is retrieved as below code but  when tried like this with link button error is showing.Thanks

    <script>

    function MyFunction(e) {

    var tex11 = e.parentNode.getElementsByTagName("input")[0];    

    var tex12 = e.parentNode.getElementsByTagName("input")[12];

     tex11.disabled ="";

     tex12.disabled ="";

    }

    </script>

       

     

    Thursday, November 14, 2013 10:23 PM

Answers

  • User-417640953 posted

    Hi shsu,

    Thank you post the issue to asp.net forum.

    From your description, I see that you want to show the update linkbutton and hide the edit linkbutton and disable the textbox

    when click the edit link button. For this issue, I made a simple demo below.

    <head runat="server">
        <title></title>
        <script>
            function MyFunction(e) {
                var tex11 = e.parentNode.getElementsByTagName("input")[0];
                var link1 = e.parentNode.getElementsByTagName("a")[1];
                tex11.disabled = "";
                link1.style.display = "block";
                e.style.display = "none";
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Repeater ID="Repeater1" runat="server">
                <ItemTemplate>
                    <div>
                    
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("Name") %>' disabled="disabled"></asp:TextBox>
                    <asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="MyFunction(this); return false;">Edit</asp:LinkButton>
                    <asp:LinkButton ID="LinkButton2" runat="server"  style="display:none">Update</asp:LinkButton>
                    </div>
                </ItemTemplate>
            </asp:Repeater>
        </div>
        </form>
    </body>

    Code behind:

     protected void Page_Load(object sender, EventArgs e)
            {
                //test data
                DataTable dt = new DataTable();
                dt.Columns.Add("Name");
                dt.Rows.Add("AAA");
                dt.Rows.Add("BBB");
                dt.Rows.Add("CCC");
                this.Repeater1.DataSource = dt;
                this.Repeater1.DataBind();
            }

    Hope this helps. Thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 18, 2013 12:33 AM