如何使用javascript设置服务器控件的值?

时间:2013-10-01 07:08:04

标签: c# javascript asp.net

如果我将该服务器控件的ClientID传递给javascript,我可以设置服务器控件的值吗?

<script type="text/javascript">
    function FillTextFromPopup(text) {
        alert(text);
        var myID = '<%= Session["myID"].ToString() %>';
        alert(myID);

            document.getElementById(myID).value = 'abc';

    }
</script>


protected void LinkButton1_Click(object sender, EventArgs e)
    {
           GridViewRow gvRow = (GridViewRow)(sender as Control).Parent.Parent;
            int index = gvRow.RowIndex;
            LinkButton lnk = (LinkButton)gvRow.FindControl("LinkButton1");
            string id = lnk.ClientID;
            Session["myID"] = id;
            string myScript;
            myScript = "<script>window.open('PopUpTest1.aspx?',null,'height=750, width=1024,status= no,resizable= no, scrollbars=yes,toolbar=no,location=no,menubar=no'); </script>";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "pop", myScript, false);

    }

1 个答案:

答案 0 :(得分:0)

您需要更改LinkBut​​ton控件的innerText属性:

更改

document.getElementById(myID).value = 'abc';

document.getElementById(myID).textContent = 'abc';