How to go to code in code from javascript

I have a gridview. When I click on one line, I have to go to javascript, which looks like this.

        <script type="text/javascript" language="javascript">
            function GetDetails(rowNo)
            {
                document.getElementById('hidRowNo').value = rowNo
                document.getElementById('btnDet').click();
            }
        </script>

I wrote the following code in codebehind

    protected void btnDet_Click(object sender, EventArgs e)
    {
        if (hidRowNo.Value != "")
        {
            int rowNo = Convert.ToInt32(hidRowNo.Value);
            TextBox1.Text = GridView1.Rows[rowNo].Cells[0].Text;
            TextBox2.Text = GridView1.Rows[rowNo].Cells[1].Text;
            TextBox3.Text = GridView1.Rows[rowNo].Cells[2].Text;
        }
    }



    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onclick", "GetDetails(" + e.Row.RowIndex + ");");
        }
    }

The problem is javascript working, but document.getElementById ('btnDet'). click (); does not work. At the same time, the debugging also does not go into btnDet_Click. Which change should I include in order to move the control to btnDel_Click in the code behind.

can anyone help?

+3
source share
2 answers

What about

__doPostBack('btnDet','OnClick');

instead

document.getElementById('btnDet').click();

In the server side download box, just add this code ...

ClientScriptManager.GetPostBackEventReference(btnDet)

Mark msdn article here

But your code should also work.

. ?

+3

, onclick btnDel. , , .

document.getElementById('btnDet').click();

document.forms[0].fireevent('onsubmit');
0

Source: https://habr.com/ru/post/1715056/


All Articles