1

マスターページで使用しようとしているプロパティにフォーカスを設定していますが、それができません。

public partial class Site1 : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
            Page.MaintainScrollPositionOnPostBack = true;
            SetFocus(this);

    }
      public void SetFocus(Site1 site1)
    {
        string[] sCtrl = null;
        string sCtrlId = null;
        Control sCtrlFound = default(Control);
        string sCtrlClientId = null;
        string sScript = null;

        sCtrl = site1.Request.Form.GetValues("__EVENTTARGET");
        if ((sCtrl != null))
        {
            sCtrlId = sCtrl[0];
            sCtrlFound = site1.FindControl(sCtrlId);
            Global.logger.Info("sCtrlId = " + sCtrlId + ", " + sCtrlFound);
            if ((sCtrlFound != null))
            {
                sCtrlClientId = sCtrlFound.ClientID;
                Global.logger.Info("sCtrlClientId = " + sCtrlClientId);

                sScript = "<SCRIPT language='javascript'>document.getElementById('" + sCtrlClientId + "').focus(); if (document.getElementById('" + sCtrlClientId + "').scrollIntoView(false)) {document.getElementById('" + sCtrlClientId + "').scrollIntoView(true)} </SCRIPT>";

                site1.ClientScript.RegisterStartupScript(typeof(string), "controlFocus", sScript);

            }
        }
    }
    }

最後の行でエラーが発生します。

'System.Web.UI.MasterPage' には 'ClientScript' の定義が含まれておらず、'System.Web.UI.MasterPage' 型の最初の引数を受け入れる拡張メソッド 'ClientScript' が見つかりませんでした (using ディレクティブがありませんか?またはアセンブリ参照?)

このコードは、通常のコンテンツ ページで正常に機能します。エラーはマスターページでのみ発生します。

上記のコードを機能させるために私ができることについて何か提案はありますか?

4

1 に答える 1

1

I'm not sure if this works but it should at least compile:

Replace:

site1.ClientScript.RegisterStartupScript(typeof(string), "controlFocus", sScript);

With:

site1.Page.ClientScript.RegisterStartupScript(GetType(String), "controlFocus", sScript);
于 2011-06-02T17:50:00.253 に答える