-1

ユーザーがグリッドの[編集]ボタンをクリックすると、サイト名と注文ID(非表示の値)がjavascript関数に渡されます。1つのサイト名で「未終了の文字列定数エラー」が発生します。何が悪いのかわかりません。下の画像をご覧ください。ここに画像の説明を入力してください

protected void gvCktMap_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (Session["TaskID"] != null)
            {
                int intTskID = Convert.ToInt32(Session["TaskID"]);
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    e.Row.Attributes.Add("class", "taskListRow");
                }
                CheckBox chkBoxOne = (CheckBox)e.Row.FindControl("chkSelect");
                Label lblREJ = (Label)e.Row.FindControl("lblREJ");
                // Label lblDesc = (Label)e.Row.FindControl("lblDesc");
                Label lblStatus = (Label)e.Row.FindControl("lblTaskStatus");
                Label lblDaysUntillPTD = (Label)e.Row.FindControl("lblDaysUntilPTD");
                Label lblPastDue = (Label)e.Row.FindControl("lblPastDue");
                if (lblStatus != null)
                {
                    if (lblStatus.Text.Trim().ToLower() == "complete" || lblStatus.Text.Trim().ToLower() == "not_required")
                        chkBoxOne.Enabled = false;
                }
                //Do Not move this code...We are selecting orderids based on checkbox enable or not....//Babu//
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    LinkButton lnkSiteName = (LinkButton)e.Row.FindControl("lnkSiteName");
                    Label lblServiceOrderNumber = (Label)e.Row.FindControl("lblServiceOrderNumber");
                    LinkButton lnkCMNumber = (LinkButton)e.Row.FindControl("lnkCORECMNumber");
                    LinkButton lnkSiteCMTicketNumber = (LinkButton)e.Row.FindControl("lnkSiteCMTicketNumber");
                    LinkButton lnkSMNumber = (LinkButton)e.Row.FindControl("lnkSMTicketNumber");
                    LinkButton lnkSiteSMTicketNumber = (LinkButton)e.Row.FindControl("lnkSiteSMTicketNumber");
                    Label lblorderId = (Label)e.Row.FindControl("lblorderId");
                    Label lblsId = (Label)e.Row.FindControl("lblsId");
                    Label lblsiteId = (Label)e.Row.FindControl("lblsiteId");
                    Label lbllob = (Label)e.Row.FindControl("lblLOB");
                    Label lblclarifyAccountNumber = (Label)e.Row.FindControl("lblclarifyAccountNumber");
                    Label lblTaskStatus = (Label)e.Row.FindControl("lblTaskStatus");
                    LinkButton lnkCustomerName = (LinkButton)e.Row.FindControl("lnkCustomerName");
                    LinkButton lnkProjectName = (LinkButton)e.Row.FindControl("lnkProjectName");
                    LinkButton lnkRoeID = (LinkButton)e.Row.FindControl("lnkPreSaleAssociation");
                    ImageButton detailsbutton = (ImageButton)e.Row.FindControl("btnDetails");
                    LinkButton lnkpendingdependencies = (LinkButton)e.Row.FindControl("lnkPendingDependencies");
                    LinkButton lnknotes = (LinkButton)e.Row.FindControl("lnkNotes");
                    LinkButton lnkuserpendingdependencies = (LinkButton)e.Row.FindControl("lnkUserPendingDependences");
                    LinkButton lnkPendJeopCount = (LinkButton)e.Row.FindControl("lnkPendJeopCount");
                    LinkButton lnkPreSaleAssociation = (LinkButton)e.Row.FindControl("lnkPreSaleAssocation");
                    LinkButton lnktaskowner = (LinkButton)e.Row.FindControl("lnkTaskOwner");
                    LinkButton lnkConfigs = (LinkButton)e.Row.FindControl("lnkConfigFiles?");
                    LinkButton lnkCircuits = (LinkButton)e.Row.FindControl("lnkCircuits");
                    LinkButton lnkOptics = (LinkButton)e.Row.FindControl("lnkOptics");
                    ImageButton btnMixedorder = (ImageButton)e.Row.FindControl("btnMixedOrd");
                    ImageButton edit_button = (ImageButton)e.Row.FindControl("edit_button");
                    if (edit_button != null)
                        edit_button.OnClientClick = "StoreOrderIDAndLOB('" + lblorderId.Text + "','" + lbllob.Text + "')";

                    if (lnkConfigs != null)
                        lnkConfigs.OnClientClick = "StoreConfigs('" + lblsId.Text + "','" + lnkSiteName.Text.Replace("'", "&apos") + "')";

                    if (lnktaskowner != null)
                        lnktaskowner.OnClientClick = "StoreTaskOwner('" + lnkSiteName.Text.Replace("'", "&apos") + "','" + lnktaskowner.Text.Replace("'", "&apos") + "','" + lblorderId.Text + "','" + lbllob.Text + "','" + lblTaskStatus.Text + "')";

                    if (lnkSiteName != null)
                        lnkSiteName.OnClientClick = "StoreLnkSiteName('" + lblorderId.Text + "','" + lnkSiteName.Text.Replace("'", "&apos") + "')";

                    if (detailsbutton != null)
                        detailsbutton.OnClientClick = "Storedetails('" + lnkSiteName.Text.Replace("'", "&apos") + "')";

                    if (lnkCMNumber != null)
                        lnkCMNumber.OnClientClick = "StoreCMNumber('" + lnkCMNumber.Text + "', '" + lblorderId.Text + "')";

                    if (lnkSiteCMTicketNumber != null)
                        lnkSiteCMTicketNumber.OnClientClick = "StoreSiteCMTicketNumber('" + lnkSiteCMTicketNumber.Text + "', '" + lblorderId.Text + "')";

                    if (lnkSMNumber != null)
                        lnkSMNumber.OnClientClick = "StorelnkSMNumber('" + lnkSMNumber.Text + "', '" + lblorderId.Text + "')";

                    if (lnkSiteSMTicketNumber != null)
                    {
                        lnkSiteSMTicketNumber.OnClientClick = "StorelnkSiteSMTicketNumber('" + lnkSiteSMTicketNumber.Text + "', '" + lblorderId.Text + "')";
                    }
                    if (lnkpendingdependencies != null)
                    {
                        lnkpendingdependencies.OnClientClick = "StoreOrderId('" + lblorderId.Text + "')";
                    }
                    if (lnknotes != null)
                    {
                        lnknotes.OnClientClick = "StoreNotes('" + lblorderId.Text + "','" + lnkSiteName.Text.Replace("'", "&apos") + "')";
                    }
                    if (lnkuserpendingdependencies != null)
                    {
                        lnkuserpendingdependencies.OnClientClick = "StoreUserpendingdependencies('" + lblorderId.Text + "','" + lnkSiteName.Text.Replace("'", "&apos") + "')";
                    }
                    if (lnkPendJeopCount != null)
                    {
                        lnkPendJeopCount.OnClientClick = "StorePendJeopCount('" + lblorderId.Text + "','" + lnkSiteName.Text.Replace("'", "&apos") + "')";
                    }
                    if (lnkProjectName != null)
                    {
                        lnkProjectName.OnClientClick = "Storeprojectname('" + lnkProjectName.Text.Replace("'", "&apos") + "')";
                    }
                    if (lnkCustomerName != null)
                    {
                        lnkCustomerName.OnClientClick = "StoreCustomername('" + lnkCustomerName.Text.Replace("'", "&apos") + "')";
                    }
                    if (lnkPreSaleAssociation != null)
                    {
                        lnkPreSaleAssociation.OnClientClick = "StorePreSaleAssociation('" + lblorderId.Text.Trim() + "','" + lblsId.Text.Trim() + "','" + lblTaskStatus.Text.Trim() + "')";
                    }
                    if (lnkCircuits != null)
                    {
                        lnkCircuits.OnClientClick = "StoreCircuitsInfo('" + lblorderId.Text + "','" + lblsiteId.Text + "','" + lbllob.Text + "','" + lblclarifyAccountNumber.Text + "','" + lnkSiteName.Text.Replace("'", "&apos") + "')";
                    }
                    if (lnkOptics != null)
                    {
                        lnkOptics.OnClientClick = "StoreOpticsInfo('" + lblsId.Text + "','" + lnkSiteName.Text.Replace("'", "&apos") + "')";
                    }
                    if (btnMixedorder != null)
                    {
                        btnMixedorder.OnClientClick = "StoreMixedorder('" + lblServiceOrderNumber.Text + "')";
                    }
                }
            }
        }
        catch (Exception ex)
        {
            log4net.Config.XmlConfigurator.Configure();
            log.Warn("Logging:" + ex);
        }
    }

このエラーを解決するにはどうすればよいですか?

function StoreOrderIDAndLOB(sender) {
//get handle to parent row:
var oRow = sender;
while (oRow && oRow.tagName.toLowerCase() !== "tr")
    oRow = oRow.parentNode;

//something might be wrong, sanity check:
if (!oRow)
    return;

//build array of all possible elements we have to look into:
var elements = [];
var arrSpans = oRow.getElementsByTagName("span");
for (var i = 0; i < arrSpans.length; i++)
    elements.push(arrSpans[i]);

//site name is the sender, grab its contents:
var siteName = "";
for (var i = 0; i < elements.length; i++) {
    var element = elements[i];
    if (element.id.indexOf("lnkSiteName") >= 0) {
        siteName = element.innerHTML;
        break;
    }
}
siteName = sender.innerHTML;

//find the order ID by looking for matching element:
var orderId = "";
for (var i = 0; i < elements.length; i++) {
    var element = elements[i];
    if (element.id.indexOf("lblorderId") >= 0) {
        orderId = element.innerHTML;
        break;
    }
}

//here you can use the values same way you use in the original code...
alert("site name: " + siteName + " and order ID is " + orderId);

}

4

2 に答える 2

0

これは、パラメータが正しく渡されていないことを意味します。コードを貼り付けてもらえますか?何が渡されるかを確認するためにブレークポイントを設定してみましたか?

于 2012-10-03T15:37:13.297 に答える
0

1つの値に二重引用符が含まれるのに十分であり、そのような場合は出力自体が壊れているため、すべてが壊れます。

生の値をJavaScript関数に送信する代わりに、関数に必要な値を見つけさせます。1つの関数の例を示します。他のすべての関数に同じロジックを適用し、引用符のリスクなしにクリーンなコードを作成できます。

JavaScript:

function StoreLnkSiteName(sender) {
    //get handle to parent row:
    var oRow = sender;
    while (oRow && oRow.tagName.toLowerCase() !== "tr")
        oRow = oRow.parentNode;

    //something might be wrong, sanity check:
    if (!oRow)
        return;

    //build array of all possible elements we have to look into:
    var elements = [];
    var arrSpans = oRow.getElementsByTagName("span");
    for (var i = 0; i < arrSpans.length; i++)
        elements.push(arrSpans[i]);

    //site name is the sender, grab its contents:
    var siteName = sender.innerHTML;

    //find the order ID by looking for matching element:
    var orderId = "";
    for (var i = 0; i < elements.length; i++) {
        var element = elements[i];
        if (element.id.indexOf("lblorderId") >= 0) {
            orderId = element.innerHTML;
            break;
        }
    }

    //here you can use the values same way you use in the original code...
    alert("site name: " + siteName + " and order ID is " + orderId);
}

その場合、必要なC#は単純です。

lnkSiteName.OnClientClick = "StoreLnkSiteName(this)";

交換する必要はなく、引用を恐れる必要もありません。

ライブテストケース

jQueryを使用することにした場合、JavaScriptコードを大幅に簡略化できますが、純粋なJSでも実現できます。

于 2012-10-03T16:06:47.383 に答える