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. ASP.NET
  4. Disable a hyperlink

Disable a hyperlink

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelp
10 Posts 3 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.
  • M Offline
    M Offline
    MacIntyre
    wrote on last edited by
    #1

    I have a datagrid with various BoundColumns and HyperLinkColumns. All of the columns work great. The problem is that I am creating a list for data entry. If the data has already been entered I want to disable the Entry Hyperlink and Enable the View/Edit Hyperlink, and visa versa if the entry has not been made I want the Entry HyperLink to be Enabled and the View/Edit HyperLink to be Disabled. If there was a way to create an ID for the column I could handle it in the ItemDataBound Event in the behind code, but I have not found a way to create an ID field for the HyperLinkColumn. Could someone assist with a code sample for ASP.NET...

    A B 2 Replies Last reply
    0
    • M MacIntyre

      I have a datagrid with various BoundColumns and HyperLinkColumns. All of the columns work great. The problem is that I am creating a list for data entry. If the data has already been entered I want to disable the Entry Hyperlink and Enable the View/Edit Hyperlink, and visa versa if the entry has not been made I want the Entry HyperLink to be Enabled and the View/Edit HyperLink to be Disabled. If there was a way to create an ID for the column I could handle it in the ItemDataBound Event in the behind code, but I have not found a way to create an ID field for the HyperLinkColumn. Could someone assist with a code sample for ASP.NET...

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      It could be done easily using this :

      .disabledLink
      {
      color: #333;
      text-decoration : none;
      cursor: default;
      }

      Use this Javascript to do this in client side.

      function disablelink(linkID)
      {
      var hlink = document.getElementById(linkID);
      if(!hlink)
      return;

      hlink.href = "#";
      hlink.className = "disableLink";
      }

      or in ItemDataBound use :

      ctrl.CssClass = "disabledLink";
      ctrl.Href = "#";

      It will be disabled. :cool: Why do you require to create ID. If you place the server side ID, you might use ClientId to get what id is generated in the client. ;)

      Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


      My Latest Articles-->** Simplify Code Using NDepend
      Basics of Bing Search API using .NET
      Microsoft Bing MAP using Javascript

      1 Reply Last reply
      0
      • M MacIntyre

        I have a datagrid with various BoundColumns and HyperLinkColumns. All of the columns work great. The problem is that I am creating a list for data entry. If the data has already been entered I want to disable the Entry Hyperlink and Enable the View/Edit Hyperlink, and visa versa if the entry has not been made I want the Entry HyperLink to be Enabled and the View/Edit HyperLink to be Disabled. If there was a way to create an ID for the column I could handle it in the ItemDataBound Event in the behind code, but I have not found a way to create an ID field for the HyperLinkColumn. Could someone assist with a code sample for ASP.NET...

        B Offline
        B Offline
        bhavnvyas
        wrote on last edited by
        #3

        protected void gvPaymentDetails_RowDataBound(object sender, GridViewRowEventArgs e)
        {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
        GridViewRow gvr = e.Row;

                if (gvr.Cells\[5\].Text != " " || gvr.Cells\[6\].Text != " " || gvr.Cells\[8\].Text != "0")
                {
                    ((LinkButton)(e.Row.FindControl("lbEdit"))).Enabled = false;
                    ((LinkButton)(e.Row.FindControl("lbEntry"))).Enabled = True;
                }
                else
                {
                 ((LinkButton)(e.Row.FindControl("lbEdit"))).Enabled = True;
                 ((LinkButton)(e.Row.FindControl("lbEntry"))).Enabled =False;
        
                }
                
        
               
        
            }
        }
        

        I am using this code in my appliction for edit and add button.

        M 1 Reply Last reply
        0
        • B bhavnvyas

          protected void gvPaymentDetails_RowDataBound(object sender, GridViewRowEventArgs e)
          {
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
          GridViewRow gvr = e.Row;

                  if (gvr.Cells\[5\].Text != " " || gvr.Cells\[6\].Text != " " || gvr.Cells\[8\].Text != "0")
                  {
                      ((LinkButton)(e.Row.FindControl("lbEdit"))).Enabled = false;
                      ((LinkButton)(e.Row.FindControl("lbEntry"))).Enabled = True;
                  }
                  else
                  {
                   ((LinkButton)(e.Row.FindControl("lbEdit"))).Enabled = True;
                   ((LinkButton)(e.Row.FindControl("lbEntry"))).Enabled =False;
          
                  }
                  
          
                 
          
              }
          }
          

          I am using this code in my appliction for edit and add button.

          M Offline
          M Offline
          MacIntyre
          wrote on last edited by
          #4

          Will ASP.NEt treat the LinkButton the same as the HyperlinkColumn with all of the same properties like DataNavigateUrlField and DataNavigateUrlFormatString?

          B 1 Reply Last reply
          0
          • M MacIntyre

            Will ASP.NEt treat the LinkButton the same as the HyperlinkColumn with all of the same properties like DataNavigateUrlField and DataNavigateUrlFormatString?

            B Offline
            B Offline
            bhavnvyas
            wrote on last edited by
            #5

            i think it will work in hyperlink columns 2 but why dont u use this code

            <Columns>
            asp:TemplateColumn
            <ItemTemplate>
            <asp:LinkButton ID="lnkEdit" runat="server">Edit</asp:LinkButton>
            <asp:LinkButton ID="lnkView" runat="server">View</asp:LinkButton>
            </ItemTemplate>
            </asp:TemplateColumn>
            </Columns>

            use itemtemplate for hyperlinks

            M 3 Replies Last reply
            0
            • B bhavnvyas

              i think it will work in hyperlink columns 2 but why dont u use this code

              <Columns>
              asp:TemplateColumn
              <ItemTemplate>
              <asp:LinkButton ID="lnkEdit" runat="server">Edit</asp:LinkButton>
              <asp:LinkButton ID="lnkView" runat="server">View</asp:LinkButton>
              </ItemTemplate>
              </asp:TemplateColumn>
              </Columns>

              use itemtemplate for hyperlinks

              M Offline
              M Offline
              MacIntyre
              wrote on last edited by
              #6

              Where do you handle the actual navigational link and column header information?

              B 1 Reply Last reply
              0
              • B bhavnvyas

                i think it will work in hyperlink columns 2 but why dont u use this code

                <Columns>
                asp:TemplateColumn
                <ItemTemplate>
                <asp:LinkButton ID="lnkEdit" runat="server">Edit</asp:LinkButton>
                <asp:LinkButton ID="lnkView" runat="server">View</asp:LinkButton>
                </ItemTemplate>
                </asp:TemplateColumn>
                </Columns>

                use itemtemplate for hyperlinks

                M Offline
                M Offline
                MacIntyre
                wrote on last edited by
                #7

                Wouldn't you have to handle that in the Code Behind... My predecessor developed this is VB

                1 Reply Last reply
                0
                • B bhavnvyas

                  i think it will work in hyperlink columns 2 but why dont u use this code

                  <Columns>
                  asp:TemplateColumn
                  <ItemTemplate>
                  <asp:LinkButton ID="lnkEdit" runat="server">Edit</asp:LinkButton>
                  <asp:LinkButton ID="lnkView" runat="server">View</asp:LinkButton>
                  </ItemTemplate>
                  </asp:TemplateColumn>
                  </Columns>

                  use itemtemplate for hyperlinks

                  M Offline
                  M Offline
                  MacIntyre
                  wrote on last edited by
                  #8

                  I like the looks of this implementation except that it feel like a total rewrite of the ASP page because the page binds data to both BoundColumns and HyperLinkColumns. To date I have not attempted to bind data to a LinkButton. Is this possible? or would I Have to move all of the naturally bound data to the ItemDataBound method and then launch the enbedded JavaScript from the ItemCommand method?

                  B 1 Reply Last reply
                  0
                  • M MacIntyre

                    Where do you handle the actual navigational link and column header information?

                    B Offline
                    B Offline
                    bhavnvyas
                    wrote on last edited by
                    #9

                    asp:TemplateField
                    <ItemTemplate>

                                                                        <asp:LinkButton ID="lbEdit" runat="server" Text="Edit" OnClick="lbEdit\_Click"></asp:LinkButton>
                                                                    </ItemTemplate>
                                                                </asp:TemplateField>
                    

                    i am redirecting from aspx only.

                    LinkButton btn = sender as LinkButton;
                    GridViewRow gvr = btn.NamingContainer as GridViewRow;
                    string docNo = gvr.Cells[0].Text;

                    so this way i am fetching row datakey

                    1 Reply Last reply
                    0
                    • M MacIntyre

                      I like the looks of this implementation except that it feel like a total rewrite of the ASP page because the page binds data to both BoundColumns and HyperLinkColumns. To date I have not attempted to bind data to a LinkButton. Is this possible? or would I Have to move all of the naturally bound data to the ItemDataBound method and then launch the enbedded JavaScript from the ItemCommand method?

                      B Offline
                      B Offline
                      bhavnvyas
                      wrote on last edited by
                      #10

                      plz send me your code so it'll be more clear. Why Do Some People Forget To Mark as Answer .If It Helps.

                      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