Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. onclick is not working

onclick is not working

Scheduled Pinned Locked Moved Web Development
htmldatabasesysadminhelptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nafiseh Salmani
    wrote on last edited by
    #1

    I want to create a switch button to turn on and off status. the problem is this button should be inside a repeater. I dont know how to change on to off and how to pass the the required parameter to save the changes to DB. The following code is not working and also it is not complete. here is HTML code :

    <asp:Repeater ID="RptRulesAndAlerts" runat="server"
    onitemdatabound="RptRulesAndAlerts_ItemDataBound" >
    <SeparatorTemplate>
    <br />
    </SeparatorTemplate>
    <ItemTemplate>

    <tr valign="middle">
    <td width="20%" align="center" valign="middle">
    <asp:Panel ID="pnl_status" runat="server" >

     </asp:Panel>
    

    </td>

    </tr>

    </table>
    </asp:Panel>
    </div>

    </ItemTemplate>
    </asp:Repeater>

    I am adding the switch button in code behind:

    protected void RptRulesAndAlerts_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem )
    {
    ISRulesAndAlertsDisplay display = e.Item.DataItem as ISRulesAndAlertsDisplay;

    Panel pnl_status = e.Item.FindControl("pnl_status") as Panel;
    if (display.Status < 0) //show default Rule
    {
    HyperLink showDefaultpops = new HyperLink();
    showDefaultpops.NavigateUrl = "#";
    showDefaultpops.Text = GetLocalResourceObject(display.StatusDescription).ToString();
    showDefaultpops.ID = "libtn_DefaultRule";
    pnl_status.Controls.Add(showDefaultpops);
    }
    else //show the switch button
    {
    var div=new HtmlGenericControl("div");
    div.Attributes["class"]=string.Format("OnOff {0}",(display.Status==1)?"ON" :"OFF" );
    div.Attributes["Title"] = string.Format("Click Here to {0}", (display.Status == 1) ? "OFF" : "ON");

                    var span = new HtmlGenericControl("span");
                    span.Attributes\["class"\]="on"; 
                    span.InnerText="ON";
                    div.Controls.Add(span);
                    if (display.Status == 0) span.Style\["display"\] = "none";
                    
                    span = new HtmlGenericControl("span");
                    di
    
    Z 1 Reply Last reply
    0
    • N Nafiseh Salmani

      I want to create a switch button to turn on and off status. the problem is this button should be inside a repeater. I dont know how to change on to off and how to pass the the required parameter to save the changes to DB. The following code is not working and also it is not complete. here is HTML code :

      <asp:Repeater ID="RptRulesAndAlerts" runat="server"
      onitemdatabound="RptRulesAndAlerts_ItemDataBound" >
      <SeparatorTemplate>
      <br />
      </SeparatorTemplate>
      <ItemTemplate>

      <tr valign="middle">
      <td width="20%" align="center" valign="middle">
      <asp:Panel ID="pnl_status" runat="server" >

       </asp:Panel>
      

      </td>

      </tr>

      </table>
      </asp:Panel>
      </div>

      </ItemTemplate>
      </asp:Repeater>

      I am adding the switch button in code behind:

      protected void RptRulesAndAlerts_ItemDataBound(object sender, RepeaterItemEventArgs e)
      {
      if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem )
      {
      ISRulesAndAlertsDisplay display = e.Item.DataItem as ISRulesAndAlertsDisplay;

      Panel pnl_status = e.Item.FindControl("pnl_status") as Panel;
      if (display.Status < 0) //show default Rule
      {
      HyperLink showDefaultpops = new HyperLink();
      showDefaultpops.NavigateUrl = "#";
      showDefaultpops.Text = GetLocalResourceObject(display.StatusDescription).ToString();
      showDefaultpops.ID = "libtn_DefaultRule";
      pnl_status.Controls.Add(showDefaultpops);
      }
      else //show the switch button
      {
      var div=new HtmlGenericControl("div");
      div.Attributes["class"]=string.Format("OnOff {0}",(display.Status==1)?"ON" :"OFF" );
      div.Attributes["Title"] = string.Format("Click Here to {0}", (display.Status == 1) ? "OFF" : "ON");

                      var span = new HtmlGenericControl("span");
                      span.Attributes\["class"\]="on"; 
                      span.InnerText="ON";
                      div.Controls.Add(span);
                      if (display.Status == 0) span.Style\["display"\] = "none";
                      
                      span = new HtmlGenericControl("span");
                      di
      
      Z Offline
      Z Offline
      ZurdoDev
      wrote on last edited by
      #2

      You may want to look at the actual html that is getting rendered and see what is getting generated.

      There are only 10 types of people in the world, those who understand binary and those who don't.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups