自定义控件CS类中注册JS脚本并调用JS事件

来源:互联网 发布:eyeone软件 编辑:程序博客网 时间:2024/05/17 06:01

/// <summary>
  ///
  /// </summary>
  /// <param name="writer"></param>
  protected override void Render(HtmlTextWriter writer)
  {
   string strEnableStr=Enabled ? "1" : "0";
   string strAutoPostBack= AutoPostBack ? "true":"false";
   try
   {
    if (Enabled)
    {
     m_picDate.Style.Remove("filter");
     m_hitDateInput.ReadOnly=false;
    }
    else
    {
     m_picDate.Style.Remove("filter");
     m_picDate.Style.Add("filter" ,"progid:DXImageTransform.Microsoft.BasicImage(grayScale=1);");
     m_hitDateInput.ReadOnly=true;


                    string strBlock = "function GetDateTime(){document.getElementById('" + m_hitDateInput.ClientID + "').readOnly=true;document.getElementById('" + m_hitDateInput.ClientID + "').value='" + m_hitDateInput.Text + "';}";
                    Page.ClientScript.RegisterStartupScript(Page.GetType(), "MyScript", strBlock, true);
                   // m_hitDateInput.Attributes["onblur"] = "GetDateTime();";
                    m_hitDateInput.Attributes["onmousedown"] = "GetDateTime();";
                    m_hitDateInput.Attributes["onchange"] = "GetDateTime();";
                  

    }
   }
   catch
   {
   }
   
   if(this.Format == FormatEnum.Date)
   {
   
    this.m_picDate.Attributes["onClick"]="setDate('"+GetDateInputClientName()+"','"+strEnableStr+"','"+this.ID+"','"+ this.CssType +"',"+strAutoPostBack+");";
   }
   else
   {
    this.m_picDate.Attributes["onClick"]="setDateTime('"+GetDateInputClientName()+"','"+strEnableStr+"','"+this.ID+"','"+ this.CssType +"',"+strAutoPostBack+");";
   }
   if (AutoPostBack)
   {
                m_hitDateInput.Attributes["onchange"] = Page.ClientScript.GetPostBackEventReference(this, String.Empty) + ";";
   }
   m_hitDateInput.Attributes["id"]=m_hitDateInput.ClientID;
//   bool blnEnabled=Enabled;
   Enabled=true;
   base.Render (writer);
//   Enabled=blnEnabled;
  }