Setfocus () на главной странице

У меня установлен фокус для свойства, которое я пытаюсь использовать на главной странице, но я не могу этого сделать.

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' does not contain a definition for 'ClientScript' and no extension method 'ClientScript' accepting a first argument of type 'System.Web.UI.MasterPage' could be found (are you missing a using directive or an assembly reference?)

Этот код отлично работает на обычной странице содержимого. Ошибка возникает только на главной странице.

Есть ли у вас какие-либо предложения относительно того, что я могу сделать, чтобы приведенный выше код работал?


person user175084    schedule 02.06.2011    source источник


Ответы (1)


Я не уверен, работает ли это, но он должен хотя бы скомпилировать:

Заменять:

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

С участием:

site1.Page.ClientScript.RegisterStartupScript(GetType(String), "controlFocus", sScript);
person Tim Schmelter    schedule 02.06.2011