This is a migrated thread and some comments may be shown as answers.

Add event client side handler dynamically

2 Answers 339 Views
Input
This is a migrated thread and some comments may be shown as answers.
Harry Kable
Top achievements
Rank 1
Harry Kable asked on 26 Apr 2010, 11:15 AM
Hi
I am creating RadTextBox and RadComboBoc controls dynamically from information stored in a database.
Can you please expalin how I can wire up a client side event as each control is created. I am mainly using the OnValueChanged and OnClientSelectedIndexChanged events, respectively.
Could I have answered this myself from the online help?
Regards
Harry Kable

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 Apr 2010, 01:38 PM
Hello Harry,

Here is the code snippet that I tried in my application in order to attach client events to RadTextBox/RadComboBox when created dynamically. Give a try with this approach.

CS:
protected void Page_Load(object sender, EventArgs e) 
 { 
   RadTextBox textbox = new RadTextBox(); 
   textbox.ClientEvents.OnValueChanged = "ValueChanged";//attaching client side events 
   this.form1.Controls.Add(textbox); 
 
   RadComboBox combo = new RadComboBox(); 
   combo.DataTextField = "user_role"
   combo.DataValueField = "user_role"
   combo.DataSourceID = "SqlDataSource2"
   combo.OnClientSelectedIndexChanged = "ClientSelectedIndexChanged";//attaching client side events 
   this.form1.Controls.Add(combo); 

JAVA SCRIPT:
<script type="text/javascript"
    function ClientSelectedIndexChanged(sender, args) { 
        alert("ClientSelectedIndexChanged fired"); 
    } 
    function ValueChanged(sender, args) { 
        alert("ValueChanged fired"); 
    } 
</script> 

Regards,
Shinu.



0
Harry Kable
Top achievements
Rank 1
answered on 26 Apr 2010, 01:46 PM
Hi Shinu
Thank you so much for your quick response.
The answer is much simplier than I expected.
I guess to become a master takes time.
Regards
Harry Kable
Tags
Input
Asked by
Harry Kable
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Harry Kable
Top achievements
Rank 1
Share this question
or