Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用RegisterStartupScript为Gridview控件注册带有参数的javascript方法_Javascript_C#_Asp.net_Gridview_Registerstartupscript - Fatal编程技术网

使用RegisterStartupScript为Gridview控件注册带有参数的javascript方法

使用RegisterStartupScript为Gridview控件注册带有参数的javascript方法,javascript,c#,asp.net,gridview,registerstartupscript,Javascript,C#,Asp.net,Gridview,Registerstartupscript,我在用户控件ascx中有一个网格视图控件。此网格视图的控件必须使用java脚本事件注册。我的问题是,如何使用RegisterStartupScript注册这些Javascript事件!作为一种解决方法,我目前已将Javascript方法放在调用页面aspx中。代码如下所示 ascx: ascx.cs protected void gvCreateClaim_RowDataBound(object sender, GridViewRowEventArgs e) {

我在用户控件ascx中有一个网格视图控件。此网格视图的控件必须使用java脚本事件注册。我的问题是,如何使用RegisterStartupScript注册这些Javascript事件!作为一种解决方法,我目前已将Javascript方法放在调用页面aspx中。代码如下所示

ascx:

ascx.cs

        protected void gvCreateClaim_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType != DataControlRowType.DataRow)
            return;
        LinkButton linkButton = (LinkButton)e.Row.Cells[3].Controls[1];

        TextBox txtDamageDetails = (TextBox)e.Row.Cells[2].Controls[1];

        Panel pnlDamageDetails = (Panel)e.Row.Cells[2].FindControl("pnlDamageDetails");
        RadioButtonList rblDamageDetails = (RadioButtonList)pnlDamageDetails.FindControl("rblDamageDetails");
        for (int i = 0; i < rblDamageDetails.Items.Count; i++)
            rblDamageDetails.Items[i].Attributes.Add("onclick", "setTextValue('" + txtDamageDetails.ClientID + "','" + rblDamageDetails.Items[i].Text + "','" + pnlDamageDetails.ClientID + "');");

        txtDamageDetails.Attributes.Add("onkeypress", "return false;");

        if (ClaimsData.Count == 1)
            linkButton.OnClientClick = "alert('At least one line item is needed in order to continue with Claim process');return false;";
        else
            linkButton.OnClientClick = "return confirm('Are you sure, you want to delete the S.No # " + e.Row.Cells[0].Text + "?');";
        //This below line is not working
        ScriptManager.RegisterStartupScript(this, this.GetType(), "setTextValue(textBoxID, text, panelID)", "$get(textBoxID).value = text;$get(panelID).style.display = 'None';", true);
    }
aspx:


我不想在aspx中编写Javascript方法setTextValue。相反,它可以从ascx的RegisterStartupScript中工作。

为什么要在代码背后这样做?如果您使用jquery.John,您不能将这些都放在document.ready函数或$function{}中吗?谢谢您的回复。我需要一种在.cs文件中编写此脚本的方法。有什么建议吗!?
        protected void gvCreateClaim_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType != DataControlRowType.DataRow)
            return;
        LinkButton linkButton = (LinkButton)e.Row.Cells[3].Controls[1];

        TextBox txtDamageDetails = (TextBox)e.Row.Cells[2].Controls[1];

        Panel pnlDamageDetails = (Panel)e.Row.Cells[2].FindControl("pnlDamageDetails");
        RadioButtonList rblDamageDetails = (RadioButtonList)pnlDamageDetails.FindControl("rblDamageDetails");
        for (int i = 0; i < rblDamageDetails.Items.Count; i++)
            rblDamageDetails.Items[i].Attributes.Add("onclick", "setTextValue('" + txtDamageDetails.ClientID + "','" + rblDamageDetails.Items[i].Text + "','" + pnlDamageDetails.ClientID + "');");

        txtDamageDetails.Attributes.Add("onkeypress", "return false;");

        if (ClaimsData.Count == 1)
            linkButton.OnClientClick = "alert('At least one line item is needed in order to continue with Claim process');return false;";
        else
            linkButton.OnClientClick = "return confirm('Are you sure, you want to delete the S.No # " + e.Row.Cells[0].Text + "?');";
        //This below line is not working
        ScriptManager.RegisterStartupScript(this, this.GetType(), "setTextValue(textBoxID, text, panelID)", "$get(textBoxID).value = text;$get(panelID).style.display = 'None';", true);
    }
<script>
function setTextValue(textBoxID, text, panelID) {
        $get(textBoxID).value = text;
        $get(panelID).style.display = "None";
    }
</script>