8 Ocak 2013 Salı

using javascript with multiple user controls

When using the same user control multiple times in the same page, accessing the user controls with javascript may be problematic, since locating a specific user control (i mean to seperate the user controls from each other) is a bit tricky.
In my condition, i solved by using a prefix as follows:
1:  function RowSelectionChanged(sender, eventArgs) {  
2:    if (sender != null) {  
3:      // to access a component in this user control  
4:      var prefix = sender.ClientID.substring(0, sender.ClientID.lastIndexOf("_"));  
5:      var param1= document.getElementById( prefix + '<%= "_LabelParam1" %>').value;  
6:      // to access a component in the main page  
7:      var prefixMainPage = sender.ClientID.substring(0, sender.ClientID.lastIndexOf("MyUserControl"));  
8:      var param2= document.getElementById(prefixAnaSayfa + '<%= "HiddenParam"%>').value;  
9:    }  
10:  }  

Hiç yorum yok:

Yorum Gönder