Skip to main content Skip to footer

Inheriting Wijmo Controls

Studio for ASP.NET Wijmo provides a complete development toolkit for creating and styling perfect web applications. It contains more than 40 controls which can cater all the needs of a project. Each control contains many inbuilt properties, events etc. and also, allows you to customize it. You may also inherit Wijmo controls in order to add more properties or override any behavior. However, when an user control or a class is inherited from any Wijmo Control then following error is observed : "Microsoft JScript runtime error: Object doesn’t support property or method ‘objectName’." This happens because Wijmo controls registers the initial js script to the client-side according to the class name (that too, in lower case). Let's say, name of Inherited Class/UserControl is 'MyCustomWijmo', so the initial js script for Inherited class will be registered as 'mycustomwijmo' but actually, there is no js object with name 'mycustomwijmo'. To resolve this issue, you just need to register the script block to client-side in your inherited control with few lines of code like this :


C#.NET  
//for C1TreeView control  
protected override void OnPreRender(EventArgs e)  
 {  
   base.OnPreRender(e);  
   RegisterScript();  
 }  

private void RegisterScript()  
 {  
  this.Page.ClientScript.RegisterStartupScript(this.GetType(), this.ID + "_script", "<script>$.fn.mycustomwijmo = $.fn.c1treeview</script>");  
  //dosomething  
 }  


VB.NET  
'for C1TreeView control  
Protected Overrides Sub OnPreRender(e As EventArgs)  
  MyBase.OnPreRender(e)  
  RegisterScript()  
End Sub  

Private Sub RegisterScript()  
  Me.Page.ClientScript.RegisterStartupScript(Me.[GetType](), Me.ID + "_script", "<script>$.fn.mycustomwijmo = $.fn.c1treeview></script>")  
  'dosomething  
End Sub  

Similarly, you can add the above code for inheriting other Wijmo controls as well. For Example, you may use the following code for C1GridView control:


C#.NET  
public class CustomC1GridView : C1.Web.Wijmo.Controls.C1GridView.C1GridView  
 {  
   private void RegisterScript()  
   {  
    this.Page.ClientScript.RegisterStartupScript(this.GetType(), this.ID + "_script", "<script>$.fn.customc1gridview = $.fn.c1gridview></script>");  
    //dosomething  
   }  
   protected void Page_Load(object sender, EventArgs e)  
   {  
   }  
}  


VB.NET  
Public Class CustomC1GridView  
     Inherits C1.Web.Wijmo.Controls.C1GridView.C1GridView  
 Private Sub RegisterScript()  
   Me.Page.ClientScript.RegisterStartupScript(Me.[GetType](), Me.ID + "_script", "<script>$.fn.customc1gridview = $.fn.c1gridview></script>")  
   'dosomething  
 End Sub  
 Protected Sub Page_Load(sender As Object, e As EventArgs)  
 End Sub  
End Class  

Thats it. Now, you can create the custom Wijmo controls as required in your project. Sample

MESCIUS inc.

comments powered by Disqus