[CLOSED] How to add DirectEvents to Radio controls using code behind?

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] How to add DirectEvents to Radio controls using code behind?

    Hi,

    I am creating some radio buttons dynamically using code behind and I need to add the ( <Check OnEvent="RadioButton_Click" />) event to them on DirectEvents. Like is done in the following code.

    Could you tell me please how to do it?


                 <ext:Radio ID="RadioHotTopic1" runat="server" Cls="radioButtonHotTopics" GroupName="hotTopics">
                        <DirectEvents>
                            <Check OnEvent="RadioButton_Click" />
                        </DirectEvents>
                    </ext:Radio>
    Last edited by geoffrey.mcgill; Aug 11, 2010 at 8:12 AM. Reason: [CLOSED]
  2. #2
    Hi,

    Either of the following options will work.

    Example

    this.Radio1.DirectCheck += RadioButton_Click;
    this.Radio1.DirectEvents.Check.Event += RadioButton_Click;
    Hope this helps.
    Geoffrey McGill
    Founder
  3. #3
    Hi,

    I am attahcing the error that I got when I set the direct event by code behind.

     
           Ext.Net.Radio RadioHotTopic = new Ext.Net.Radio();
           RadioHotTopic.DirectEvents.Check.Event += RadioButton_Click;
     
     
            protected void RadioButton_Click(object sender, DirectEventArgs e)
            {
            }
    Attached Thumbnails Click image for larger version. 

Name:	ErrorRadioDirectEvent.jpg 
Views:	174 
Size:	97.9 KB 
ID:	1466  
  4. #4
    Hi Flor,

    I tested your code and it works correctly.
    Geoffrey McGill
    Founder
  5. #5
    Hi,

    It is hard to find what is the problem here. I created a new page just creating some radio buttons dynamically and setting the check event and that worked fine, but I am still with that error in my code. If I press ingnore after that error it shows me the followin message:


    Server Error in '/ChampWeb' Application.

    The control with ID 'RadioHotTopic2' not found

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: The control with ID 'RadioHotTopic2' not found

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
    Stack Trace:

    [HttpException (0x80004005): The control with ID 'RadioHotTopic2' not found] Ext.Net.ResourceManager.RaisePostBackEvent(String eventArgument) +1083 System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +175 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

    Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3614


    I putted my whole code here to see if can help me.


    <%@ Page Language="C#" AutoEventWireup="True" CodeBehind="iNed.aspx.cs" Inherits="ChampWeb.iNed" Title="<%$ Resources:Resource, pageTitle %>"%>
    <%@ Import Namespace="System.ComponentModel" %>
    <%@ Import Namespace="System.Xml.XPath" %>
    <%@ Import Namespace="System.Data"%>
    <%@ Import Namespace="System.Data.SqlClient"%>
    <%@ Import Namespace="System.Threading"%>
    <%@ Import Namespace="System.Globalization"%>
    <%@ Import Namespace="ChampWeb.Util" %>
    <%@ Import Namespace="ChampWeb.Data" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <link href="App_Themes/ChampWeb/Default.css" rel="stylesheet" type="text/css" />    
        <title></title>
        
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!X.IsAjaxRequest)
                {
                    // Update xml playlist file from DB
                    MessageBoxConfig msg = new MessageBoxConfig();
                    msg.Message = XMLManagement.AddMP3s();
                        
                    if (msg.Message != null)
                    {
                        X.MessageBox.Show(msg);
                        X.MessageBox.Call("getDialog().setPosition", new object[] { 0, 0 });
                    }
                    FlashComponentRadioNedActive.Url = this.ResolveUrl(@"~\App_Themes\ChampWeb\Animations\iNedActive.swf");
                    loadHotTopics();
                }
            }
            protected void loadHotTopics()
            {
                string ConnectionString = ConfigurationManager.ConnectionStrings["JTechConsulting.Data.Orm.SqlServer"].ConnectionString;
                int hotTopicNumber = setHotTopics(ConnectionString);
                if (hotTopicNumber >= 2)
                {
                    string hotTopicVoteID = getUserVote(ConnectionString);
                    if (hotTopicVoteID != null && !String.IsNullOrEmpty(hotTopicVoteID))
                    {
                        selectHotTipic(hotTopicVoteID, hotTopicNumber);
                        this.ImageButtonVote.Disabled = true;
                    }
                    if (hotTopicNumber > 2)
                    {
                        int panelHeight = Convert.ToInt32(this.PanelHotTopicsContent.Height.Value) + ((hotTopicNumber - 2) * 57);
                        this.PanelHotTopicsContent.Height = panelHeight;
                    }
                }
                else
                {
                    this.PanelHotTopicsContent.Hidden = true;
                }
            }
            
            protected int setHotTopics(string ConnectionString)
            {
                string hotTopicID;
                string hotTopicDescription;
                int hotTopicNumber = 0;
                string culture = Session["curCulture"].ToString();
                string hotTopicLabel = (String)GetGlobalResourceObject("Resource", "LabelTotalHotTopicVote");
                            
                HOTTOPICFactory hotTopicFactory = new HOTTOPICFactory();
                BindingList<HOTTOPIC> hotTopics = hotTopicFactory.FetchCurrentHotTopics(ConnectionString, culture);
                foreach (HOTTOPIC curHotTopic in hotTopics)
                {
                   hotTopicNumber++;
                   hotTopicID = curHotTopic.ID.ToString();
                   hotTopicDescription = curHotTopic.DESCRIPTION;
                   Ext.Net.Radio RadioHotTopic = new Ext.Net.Radio();
                   RadioHotTopic.ID = "RadioHotTopic" + hotTopicNumber.ToString();
                   RadioHotTopic.BoxLabel = setHotTopicsDescription(hotTopicDescription);
                   RadioHotTopic.Tag = hotTopicID;
                   RadioHotTopic.GroupName = "hotTopics";
                   RadioHotTopic.Cls = "radioButtonHotTopics";
                   RadioHotTopic.DirectEvents.Check.Event += RadioButton_Check;
                   PanelHotTopicsContent.Add(RadioHotTopic);
                   setTotalValuesToHotTopic(ConnectionString, int.Parse(hotTopicID));                
                }
                return hotTopicNumber;
            }
            
            protected void setTotalValuesToHotTopic(string ConnectionString, int hotTopicID)
            {
                SqlConnection conn = null;
                SqlCommand cmd = null;
                try
                {
                    string hotTopicDescription;
                    string hotTopicTotalText = (String)GetGlobalResourceObject("Resource", "LabelTotalHotTopicVote");
                    
                    // Retrieves the total of votes for an specific Hot topic.
                    string CommandText = "SELECT Count(*)" +
                                         "  FROM HOTTOPICVOTE" +
                                         " WHERE (HOTTOPICID = @hotTopicID)";
                    // Open connection to the database
                    conn = new SqlConnection(ConnectionString);
                    conn.Open();
                    cmd = new SqlCommand(CommandText);
                    cmd.Connection = conn;
                    // Add paramters
                    cmd.Parameters.Add(new SqlParameter("@hotTopicID", System.Data.SqlDbType.Int));
                    // Set total votes to hot topics
                    cmd.Parameters["@hotTopicID"].Value = hotTopicID;
                    Ext.Net.Label LabelTotalHotTopicVote = new Ext.Net.Label();
                    LabelTotalHotTopicVote.Text = Convert.ToString(cmd.ExecuteScalar()) + " " + hotTopicTotalText;
                    LabelTotalHotTopicVote.Cls = "labelTotalHotTopics";
                    this.PanelHotTopicsContent.Add(LabelTotalHotTopicVote);
                }
                catch (Exception ex)
                {
                    // Print error message
                    MessageBoxConfig msg = new MessageBoxConfig();
                    msg.Message = ex.Message;
                    X.MessageBox.Show(msg);
                    X.MessageBox.Call("getDialog().setPosition", new object[] { 0, 0 }); //Sets the page XY position ; 
                }
                finally
                {
                   if (conn.State == ConnectionState.Open)
                       conn.Close();
                }
            }
            protected string getUserVote(string ConnectionString)
            {
                BE_USERS be_users;
                BE_USERSFactory be_usersFactory = new BE_USERSFactory();
                SqlConnection conn = null;
                SqlCommand cmd = null;
                string result = null;
                
                try
                {
                    string hotTopicID;
                    string hotTopicDescription;
                    be_users = be_usersFactory.FetchBE_USERSOnUserName(Page.User.Identity.Name);
                    
                    // Retrieves the hotTopicID for which the user have voted
                    string CommandText = "SELECT HOTTOPICVOTE.ID" +
                                         "  FROM HOTTOPIC JOIN HOTTOPICVOTE" +
                                         "    ON (HOTTOPIC.ID = HOTTOPICVOTE.HOTTOPICID)" +
                                         " WHERE ((STARTDATE <= @today AND ENDDATE >= @today) AND USERID = @userID)";
                    // Open connection to the database
                    conn = new SqlConnection(ConnectionString);
                    conn.Open();
                    cmd = new SqlCommand(CommandText);
                    cmd.Connection = conn;
                    // Add paramters
                    cmd.Parameters.Add(new SqlParameter("@today", System.Data.SqlDbType.DateTime));
                    cmd.Parameters.Add(new SqlParameter("@userID", System.Data.SqlDbType.Int));
                    cmd.Parameters["@today"].Value = DateTime.Now;
                    cmd.Parameters["@userID"].Value = be_users.USERID;
                    result = Convert.ToString(cmd.ExecuteScalar());
                }
                catch (Exception ex)
                {
                    // Print error message
                    MessageBoxConfig msg = new MessageBoxConfig();
                    msg.Message = ex.Message;
                    X.MessageBox.Show(msg);
                    X.MessageBox.Call("getDialog().setPosition", new object[] { 0, 0 }); //Sets the page XY position ; 
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                        conn.Close();
                }
                return result;
            }
            protected void selectHotTipic(string hotTopicVoteID, int hotTopicNumber)
            {
                HOTTOPICVOTE hotTopicVote;
                HOTTOPICVOTEFactory hotTopicVoteFactory = new HOTTOPICVOTEFactory();
                hotTopicVote = hotTopicVoteFactory.FetchHOTTOPICVOTE(int.Parse(hotTopicVoteID));
                string hotTopicID = hotTopicVote.HOTTOPICID.ToString();
                
                Session["hotTopicVoteID"] = hotTopicVoteID;
                for (int curHotTopic = 1; curHotTopic < hotTopicNumber; curHotTopic++)
                {
                    Ext.Net.Radio RadioHotTopic = (Ext.Net.Radio)this.PanelHotTopicsContent.FindControl("RadioHotTopic" + curHotTopic);
                    if (RadioHotTopic.Tag == hotTopicID)
                    {
                        RadioHotTopic.Checked = true;
                    }
                }
            }
            
            protected string setHotTopicsDescription(string hotTopicDescription)
            {
                if (!String.IsNullOrEmpty(hotTopicDescription))
                {
                    string description1 = null;
                    string description2 = null;
                    if (hotTopicDescription.Length > 32)
                    {
                        description1 = hotTopicDescription.Substring(0, 32);
                        int pos = description1.LastIndexOf(" ");
                        description1 = hotTopicDescription.Substring(0, pos + 1);
                        if (hotTopicDescription.Length > 64)
                        {
                            description2 = " &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + hotTopicDescription.Substring(pos + 1, 32);
                            hotTopicDescription = description1 + description2 + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + hotTopicDescription.Substring(63);
                        }
                        else
                        {
                            description2 = " &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + hotTopicDescription.Substring(pos + 1);
                            hotTopicDescription = description1 + description2;                        
                        }
                    }
                }
                return hotTopicDescription;        
            }
            protected void ComboBoxAvatarTopics_Select(object sender, DirectEventArgs e)
            {
                int topicID = int.Parse(this.comboBoxAvatarTopics.SelectedItem.Value.ToString());
                DataBaseManagement.updateUsageTable(topicID);
                HttpContext.Current.Session["assetSelected"] = topicID;
                this.labelRatingAvatarTopics.Hidden = false;
                this.labelRatingMp3.Hidden = true;
            }
            protected void RadioButton_Check(object sender, DirectEventArgs e)
            {
                MessageBoxConfig msg = new MessageBoxConfig();
                msg.Message = "Hello Radio";
                X.MessageBox.Show(msg);
     
            }
            protected void ImageButtonVote_Click(object sender, DirectEventArgs e)
            {
                BE_USERS be_users;
                HOTTOPICVOTEFactory hotTopicsVoteFactory = new HOTTOPICVOTEFactory();
                BE_USERSFactory be_usersFactory = new BE_USERSFactory();
                
                be_users = be_usersFactory.FetchBE_USERSOnUserName(Page.User.Identity.Name);
                string hotTopicID = null;
                foreach(Control curControl in PanelHotTopicsContent.Controls)
                {
                    if (curControl is Ext.Net.Radio)
                    {
                        Ext.Net.Radio curRadioHotTopic = (Ext.Net.Radio)curControl;
                        if (curRadioHotTopic.Checked)
                        {
                            hotTopicID = curRadioHotTopic.Tag;
                        }
                    }
                }
                
                if (hotTopicID != null)
                {
                    // The current culture is changed temporarily to save the date in the format US
                    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
                    
                    // Verifies if the user have not vote yet
                    if (Session["hotTopicVoteID"] == null)
                    {
                        HOTTOPICVOTE hotTopicsVote = new HOTTOPICVOTE();
                        string ConnectionString = ConfigurationManager.ConnectionStrings["JTechConsulting.Data.Orm.SqlServer"].ConnectionString;
                        hotTopicsVote.USERID = be_users.USERID;
                        hotTopicsVote.HOTTOPICID = int.Parse(hotTopicID);
                        hotTopicsVote.VOTEDON = DateTime.Now;
                        hotTopicsVoteFactory.Insert(hotTopicsVote);
                        Session["hotTopicVoteID"] = getUserVote(ConnectionString);
                    }
                    else
                    {
                        // If the user already voted it changes the vote
                        int hotTopicVoteID = Convert.ToInt32(Session["hotTopicVoteID"]);
                        HOTTOPICVOTE hotTopicsVote = hotTopicsVoteFactory.FetchHOTTOPICVOTE(hotTopicVoteID);
                        hotTopicsVote.HOTTOPICID = int.Parse(hotTopicID);
                        hotTopicsVote.VOTEDON = DateTime.Now;
                        hotTopicsVoteFactory.Update(hotTopicsVote);
                    }
                    if (Session["curCulture"] != null)
                    {
                        Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Session["curCulture"].ToString());
                    }
                }
                this.ImageButtonVote.ImageUrl = "App_Themes/ChampWeb/Images/imaBtnStandar_Vote_Out.png";
                this.ImageButtonVote.Disabled = true;
            }
            [System.Web.Services.WebMethod(EnableSession=true)]
            public static void updateAssetRating(string rating)
            {
                if (HttpContext.Current.Session["assetSelected"] != null)
                {
                    int assetID = int.Parse(HttpContext.Current.Session["assetSelected"].ToString());
                    MessageBoxConfig msg = new MessageBoxConfig();
                    msg.Message = DataBaseManagement.updateAssetRatingTable(assetID, int.Parse(rating));
                    if (msg.Message != null)
                    {
                        X.MessageBox.Show(msg);
                        X.MessageBox.Call("getDialog().setPosition", new object[] { 0, 0 });
                    }
                }
            }
            [System.Web.Services.WebMethod(EnableSession = true)]
            public static void updateMp3Usage(string mp3ID)
            {
                HttpContext.Current.Session["assetSelected"] = mp3ID;
                MessageBoxConfig msg = new MessageBoxConfig();
                msg.Message = DataBaseManagement.updateUsageTable(int.Parse(mp3ID));
                
                if (msg.Message != null) 
                {
                    X.MessageBox.Show(msg);
                    X.MessageBox.Call("getDialog().setPosition", new object[] { 0, 0 });
                }
            }
      
        </script>
        
        <script language="JavaScript" type="text/javascript" src="http://vhss-d.oddcast.com/vhost_embe...js=1"></script>
        <script language="JavaScript" type="text/javascript">
        
        function vh_sceneLoaded(sceneIndex){
            sayAIResponse('Give WIN intro', 2, 1, 3);
        }
        
        function video()
        {
            try
            {
                var video = document.getElementById("video");
                var comboBoxContent = document.getElementById("comboBoxContent");
                var rate = document.getElementById("rate");
               
                if (video.style.display = 'none')
                { 
                    video.style.display='block';
                    comboBoxContent.style.display='block';
                    rate.style.display='none';
                    rate.style.top ='650px';
                    
                    var comboBoxAvatarTopics = document.getElementById("comboBoxAvatarTopics");
                     
                    if (comboBoxAvatarTopics != null)
                    {
                        comboBoxAvatarTopics.value = "Choose a Topic" ;
                        comboBoxContent.hidden = false;
                    }
                 }
             }
             catch(err)
             {
                alert(err.description);
             }
        }
     
        function novideo()
        {
             var video = document.getElementById("video");
             var comboBoxContent = document.getElementById("comboBoxContent");
             var comboBoxAvatarTopics = document.getElementById("comboBoxAvatarTopics");
             var rate = document.getElementById("rate"); 
             var labelRatingMp3 = document.getElementById("labelRatingMp3"); 
             var labelRatingAvatarTopics = document.getElementById("labelRatingAvatarTopics"); 
             
             video.style.display='none';
             comboBoxContent.style.display='none';
             rate.style.display='none';
             labelRatingMp3.className = "x-label x-show-display";
             labelRatingAvatarTopics.className = "x-label x-hide-display"; 
        }       
     var AskNed = function(el) 
     {
         var sayToNed = el.lastSelectionText;
         var rate = document.getElementById("rate"); 
         sayAIResponse(sayToNed, 2, 1, 3);
         rate.style.display='block';
         showRatingAnimation();
     };
       function rating(rate)
       {
            PageMethods.updateAssetRating(rate);
       } 
       
       // Function made from TSPlayer
       function songPlaying(id)
       {
         PageMethods.updateMp3Usage(id); 
         rate.style.display='block';
            showRatingAnimation();
       }
     
       function showIPlayer(swfName)
       {
            var swfUrl = './Audio/SECURE-TSPlayerV4.5.swf';
            swfobject.embedSWF(swfUrl, "iPlayerContainer", "680", "415", "10.0.0", "expressInstall.swf"); 
            PageMethods.updateUsage(swfName);
       }   
       
        function showRatingAnimation()
        {
             var swfUrl = "./App_Themes/ChampWeb/Animations/rateMe.swf";
             swfobject.embedSWF(swfUrl, "ratingSwf", "250", "30", "10.0.0", "expressInstall.swf",{}, {bgcolor: '#FFFFA9'}); 
        }
        
      </script>
         
    <style type="text/css">
        .x-combo-list .x-combo-selected 
         {
       background: #D8D855 !important;
         }
         
        .x-form-item.x-form-label-top label.x-form-item-label 
        {
         font-family: Arial, Helvetica, sans-serif;
         font-weight: bold;
         font-size:16px; 
         color:#FFC200; 
         text-align: center;
        }  
        
        .x-combo-list .x-combo-selected 
        {
            background-color: #002E12;
            border-color: #002E12 !important;
            color: #00631C;
        }   
        
        .ext-strict .x-form-text 
         {
          border-style: none;
          margin-right:1px;
         } 
         
        .x-form-field-wrap .x-form-trigger     
        {
         height: 19px !important;
        }
       </style>    
     
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" CleanResourceUrl="false">
        </ext:ResourceManager>
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" EnablePartialRendering="true">
        </asp:ScriptManager>    
        <ext:FlashComponent ID="FlashComponentRadioNedActive" runat="server" Height="0px" Width="0px"/>   
         
        <ext:Store ID="StoreAvatarTopics" runat="server" DataSourceID="ObjectDataSourceAssetTopics">
            <Reader>
                <ext:JsonReader>
                    <Fields>
                        <ext:RecordField Name="ID" />
                        <ext:RecordField Name="TITLE" />
                        <ext:RecordField Name="DISPLAYORDER" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
            <SortInfo Field="DISPLAYORDER" Direction="ASC" />
        </ext:Store>
        
            <div id="video">           
                <script type="text/javascript">AC_VHost_Embed(1185660, 300, 353, '', 1, 1, 1865677, 0, 1, 0, '86c5e6a3e4148e9e6da96074dff5d564', 9);</script>
            </div>
            
             <div id="comboBoxContent">
                    <ext:ComboBox id="comboBoxAvatarTopics" runat="server" StoreID="StoreAvatarTopics" DisplayField="TITLE" 
                                  ValueField="ID" Width="387px" Height="21px" FieldLabel="Call Dr. Ned About " 
                                  cls="comboBoxAvatarTopics" LabelAlign="Top" Text="<%$ Resources: comboBoxAvatarTopics.Text %>">
                        <Listeners>
                            <Select Fn="AskNed" />
                        </Listeners>
                        <DirectEvents>
                            <Select OnEvent="ComboBoxAvatarTopics_Select"/>
                        </DirectEvents>
                    </ext:ComboBox>
              </div> 
              
              <div id="iPlayerContainer">
                  <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/s...ersion=7,0,0,0" width="800" height="800">
                      <param name="movie" value="Audio/SECURE-TSPlayerV4.5.swf" />
                      <param name="quality" value="high" />
                      <param name="wmode" value="transparent" />
                      <param name="FlashVars" value="playlistfile=Audio/playlist.xml&configurationfile=Audio/configuration.xml&js=songPlaying" />
                      <embed src="Audio/SECURE-TSPlayerV4.5.swf" quality="high" wmode="transparent" flashvars="playlistfile=Audio/playlist.xml&configurationfile=Audio/configuration.xml&js=songPlaying" pluginspage="http://www.macromedia.com/shockwave/...ShockwaveFlash" type="application/x-shockwave-flash" width="800" height="800"></embed>
                  </object>
              </div>
             <div id="rate"> 
                   <div class="labelRatingClase">
                       <ext:Label ID="labelRatingAvatarTopics" Text="" Cls="labelRating" runat="server" 
                                   Hidden="true" meta:resourcekey="labelRatingAvatarTopics">
                       </ext:Label>
                       <ext:Label ID="labelRatingMp3" runat="server" Cls="labelRating" Hidden="true"
                                  meta:resourcekey="labelRatingMp3">
                       </ext:Label>
                       <div id="ratingSwf">
                       </div> 
                  </div>        
            </div>   
              
        <div class="panelHotTopics">
            <ext:Panel ID="PanelHotTopicsContent" runat="server" Height="220px" Width="225px" BodyCssClass="panelHotTopicsBody" 
                       Title="<%$ Resources: PanelHotTopicsContent.Title %>">
                <Content>
                    <div class="buttonsHotTopicsContent">
                        <ext:ImageButton ID="ImageButtonVote" runat="server"
                                         ImageUrl="App_Themes/ChampWeb/Images/imaBtnStandar_Vote_Out.png"
                                         OverImageUrl="App_Themes/ChampWeb/Images/imaBtnStandar_Vote_Over.png">
                              <DirectEvents>
                                 <Click OnEvent="ImageButtonVote_Click" />
                              </DirectEvents>                   
                        </ext:ImageButton>
                    </div>
                </Content>
            </ext:Panel>
       </div>
       
        <asp:ObjectDataSource ID="ObjectDataSourceAssetTopics" runat="server" 
            SelectMethod="FetchASSETOnASSETTYPE" TypeName="ChampWeb.Data.ASSETFactory">
            <SelectParameters>
                <asp:Parameter DefaultValue="3" Name="ASSETTYPE" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>    
        
      </form>
    </body>
    </html>
  6. #6
    Hi,

    Just to clarify that I got the error when I click on one of the Radios created dynamically after the page is loaded
  7. #7
    Please simplify your code sample.
    Geoffrey McGill
    Founder
  8. #8
    I think the issue is that you only create the Radio components during the Page_Load event, and do not re-create the components during the DirectEvent request.

    The Radio component does not exist in the Page Controls Collection during the second request.

    Hope this helps.
    Geoffrey McGill
    Founder
  9. #9
    Hi,

    Please note that each dynamic control must recreated on each request (including direct events)
  10. #10
    Hi,

    Here is the code again simplified:

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <link href="App_Themes/ChampWeb/Default.css" rel="stylesheet" type="text/css" />    
        <title></title>
        
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!X.IsAjaxRequest)
                {
                    loadHotTopics();
                }
            }
            protected void loadHotTopics()
            {
                int hotTopicNumber = setHotTopics(ConnectionString);
            }
            
            protected int setHotTopics(string ConnectionString)
            {
                string hotTopicID;
                string hotTopicDescription;
                int hotTopicNumber = 0;
                string culture = Session["curCulture"].ToString();
                string hotTopicLabel = (String)GetGlobalResourceObject("Resource", "LabelTotalHotTopicVote");
                            
                HOTTOPICFactory hotTopicFactory = new HOTTOPICFactory();
                BindingList<HOTTOPIC> hotTopics = hotTopicFactory.FetchCurrentHotTopics(ConnectionString, culture);
                foreach (HOTTOPIC curHotTopic in hotTopics)
                {
                   hotTopicNumber++;
                   hotTopicID = curHotTopic.ID.ToString();
                   hotTopicDescription = curHotTopic.DESCRIPTION;
                   Ext.Net.Radio RadioHotTopic = new Ext.Net.Radio();
                   RadioHotTopic.ID = "RadioHotTopic" + hotTopicNumber.ToString();
                   RadioHotTopic.BoxLabel = "RadioHotTopic";
                   RadioHotTopic.Tag = hotTopicID;
                   RadioHotTopic.GroupName = "hotTopics";
                   RadioHotTopic.Cls = "radioButtonHotTopics";
                   RadioHotTopic.DirectEvents.Check.Event += RadioButton_Check;
                   PanelHotTopicsContent.Add(RadioHotTopic);
                   setTotalValuesToHotTopic(ConnectionString, int.Parse(hotTopicID));                
                }
                return hotTopicNumber;
            }
            
            
            protected void RadioButton_Check(object sender, DirectEventArgs e)
            {
                MessageBoxConfig msg = new MessageBoxConfig();
                msg.Message = "Hello Radio";
                X.MessageBox.Show(msg);
     
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" CleanResourceUrl="false">
        </ext:ResourceManager>
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" EnablePartialRendering="true">
        </asp:ScriptManager>    
        <ext:FlashComponent ID="FlashComponentRadioNedActive" runat="server" Height="0px" Width="0px"/>   
         
        <div class="panelHotTopics">
            <ext:Panel ID="PanelHotTopicsContent" runat="server" Height="220px" Width="225px" BodyCssClass="panelHotTopicsBody" 
                       Title="<%$ Resources: PanelHotTopicsContent.Title %>">
                <Content>
                    <div class="buttonsHotTopicsContent">
                        <ext:ImageButton ID="ImageButtonVote" runat="server"
                                         ImageUrl="App_Themes/ChampWeb/Images/imaBtnStandar_Vote_Out.png"
                                         OverImageUrl="App_Themes/ChampWeb/Images/imaBtnStandar_Vote_Over.png">
                              <DirectEvents>
                                 <Click OnEvent="ImageButtonVote_Click" />
                              </DirectEvents>                   
                        </ext:ImageButton>
                    </div>
                </Content>
            </ext:Panel>
       </div>
      </form>
    </body>
    </html>
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] Build controls in code behind
    By Antonio09 in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Aug 07, 2012, 3:37 AM
  2. [CLOSED] get value of controls created in code-behind
    By vali1993 in forum 1.x Legacy Premium Help
    Replies: 18
    Last Post: Sep 30, 2010, 3:07 PM
  3. Retrieve checked radio from Radio Group
    By ttharaka2002 in forum 1.x Help
    Replies: 0
    Last Post: Mar 25, 2010, 2:15 AM
  4. Create controls in code behind
    By Yannis in forum 1.x Help
    Replies: 1
    Last Post: Nov 26, 2009, 12:03 AM
  5. [CLOSED] Dynamic Creation of Radio Buttons within Radio Group
    By Steve in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Mar 04, 2009, 1:13 PM

Posting Permissions