locked
i want to check radiobuttonlsit and <a> tag by one click in the same time using jquery RRS feed

  • Question

  • User-161996747 posted

    i have  radiobuttonlist that contain <a> tag in its listitem .

    when i click on specific positon of radiobutton ,it checked but <a> isnot fire .

    and also when i click on specific positon of radiobutton  <a> is fire but radiobutton didnot check.

    i want to check  radiobutton and <a> fire in the same time by one click

    image

    foreach (ListViewItem item in innerlistview.Items)
                        {
                            RadioButtonList RadioButtonList1 = (RadioButtonList)item.FindControl("RadioButtonList1");
                          
    
                            foreach (DataRow row in dt.Rows)
                            {
                                ListItem newitem = new ListItem();
    
                                string a = "<a href='../Uploades/ProductsColors/" + row[2].ToString() + "' class= '" + "colorss" + "'" + " style='cursor:default'" + " rel='" + "enlargeimage" + "' rev='" + "targetdiv:loadarea2,trigger:click,preload:none,fx:fade'" + ">" + "<span style=background-color:" + row[4] + "><span style=background-color:" + row[4] + "></span></span></a>";
                           
    
    
                                RadioButtonList1.Items.Add(new ListItem(a, row[3].ToString()));
                                RadioButtonList1.DataBind();
                            }
                         
                            break;
                        }
    
      protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
            {
                
                Label ResultLabel = (Label)e.Item.FindControl("ResultLabel");
                ResultLabel.Visible = false;
    
                string colortext = "";
                ListView innerlistview = (ListView)e.Item.FindControl("ColorListView");
    
                foreach (ListViewItem item in innerlistview.Items)
                {
                    RadioButtonList rad = (RadioButtonList)item.FindControl("RadioButtonList1");
                    foreach (ListItem raditem in rad.Items)
                    {
                        if (raditem.Selected)
                        {
                            colortext = raditem.Value.ToString();
    
                        }
                        else
                        {
                            ResultLabel.Text = "You must select Color . ";
                            ResultLabel.Visible = true;
                        }
                    }
    
                }
    
            }

    Wednesday, February 10, 2016 5:47 PM

Answers

  • User614698185 posted

    Hi Ahmed,

    I think you could use RadioButtonList_SelectedIndexChanged event, there is no need to use JQuery.

    I use RadioButtonList to create the sample about selecting the specific positon of RadioButton, it also fires <a> tag:

    On .aspx page:

    <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="true"
          OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
    </asp:RadioButtonList>

    On .aspx.cs page:

    using System;
    using System.Web.UI.WebControls;
    using HtmlAgilityPack; //allow you to parse "out of the web" HTML files
    
    protected void Page_Load(object sender, EventArgs e)
    {
         if (!IsPostBack)
         {
              for (int i = 1; i < 5; i++)
              {
                  string a = "<a href='Image/images/img" + i.ToString() + ".png' class= '" + "colorss" + 
                  "'" + " style='width: 100px; height: 100px; cursor: default;'" + " rel='" + "enlargeimage" + "' rev='" 
                  + "targetdiv:loadarea2,trigger:click,preload:none,fx:fade'" + ">" + "<span style=background-
                  color:pink>Item<span style=background-color:pink></span></span></a>";
    
                   RadioButtonList1.Items.Add(new ListItem(a, "Item" + i.ToString()));
                   RadioButtonList1.DataBind();
    
               }
          }
    
          RadioButtonList1.SelectedIndexChanged += RadioButtonList1_SelectedIndexChanged;
    }
    
    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
         var rbl = sender as RadioButtonList;
         var item = rbl.SelectedItem;
         var html = new HtmlDocument();
         html.LoadHtml(item.Text);
         var root = html.DocumentNode;
         var node = root.SelectSingleNode("a");
    
         Response.Redirect("/" + node.GetAttributeValue("href", ""));
    }

    Best Regards,

    Candice Zhou

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 11, 2016 2:53 AM
  • User614698185 posted

    Hi Ahmed,

    pro.agamy

    how to prevent page reload after postback ?

    As my previous post provided, use IsPostBack in the Page_Load:

    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            
        }
    }

    Best Regards,

    Candice Zhou

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 12, 2016 10:01 AM

All replies

  • User614698185 posted

    Hi Ahmed,

    I think you could use RadioButtonList_SelectedIndexChanged event, there is no need to use JQuery.

    I use RadioButtonList to create the sample about selecting the specific positon of RadioButton, it also fires <a> tag:

    On .aspx page:

    <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="true"
          OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
    </asp:RadioButtonList>

    On .aspx.cs page:

    using System;
    using System.Web.UI.WebControls;
    using HtmlAgilityPack; //allow you to parse "out of the web" HTML files
    
    protected void Page_Load(object sender, EventArgs e)
    {
         if (!IsPostBack)
         {
              for (int i = 1; i < 5; i++)
              {
                  string a = "<a href='Image/images/img" + i.ToString() + ".png' class= '" + "colorss" + 
                  "'" + " style='width: 100px; height: 100px; cursor: default;'" + " rel='" + "enlargeimage" + "' rev='" 
                  + "targetdiv:loadarea2,trigger:click,preload:none,fx:fade'" + ">" + "<span style=background-
                  color:pink>Item<span style=background-color:pink></span></span></a>";
    
                   RadioButtonList1.Items.Add(new ListItem(a, "Item" + i.ToString()));
                   RadioButtonList1.DataBind();
    
               }
          }
    
          RadioButtonList1.SelectedIndexChanged += RadioButtonList1_SelectedIndexChanged;
    }
    
    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
         var rbl = sender as RadioButtonList;
         var item = rbl.SelectedItem;
         var html = new HtmlDocument();
         html.LoadHtml(item.Text);
         var root = html.DocumentNode;
         var node = root.SelectSingleNode("a");
    
         Response.Redirect("/" + node.GetAttributeValue("href", ""));
    }

    Best Regards,

    Candice Zhou

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 11, 2016 2:53 AM
  • User-161996747 posted

    thank you @Candice Zhou for your reply .

    how to prevent page reload after postback ?

    you can see what i want in below link when click color (radiobuttonlist) ,it will check but image not change, but if u click on top of radiobutton not checked and image change .

    Link

    Thursday, February 11, 2016 2:32 PM
  • User614698185 posted

    Hi Ahmed,

    pro.agamy

    how to prevent page reload after postback ?

    As my previous post provided, use IsPostBack in the Page_Load:

    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            
        }
    }

    Best Regards,

    Candice Zhou

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 12, 2016 10:01 AM