Add event client side handler dynamically

3 posts, 0 answers
  1. Harry Kable
    Harry Kable avatar
    19 posts
    Member since:
    Jan 2010

    Posted 26 Apr 2010 Link to this post

    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. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 26 Apr 2010 Link to this post

    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.



  3. Harry Kable
    Harry Kable avatar
    19 posts
    Member since:
    Jan 2010

    Posted 26 Apr 2010 Link to this post

    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
Back to Top