Hi I am trying to disable my pager linkbuttons during postback to prevent multiple clicking as this causes the application to fall over. I have tried to use the following code but it is not working. Anyone any ideas?

Private Sub DataGrid_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid.ItemCreated

            If (e.Item.ItemType = ListItemType.Pager) Then
                

                e.Item.Attributes.Add("onclick", "this.disabled=true;")

                
            End If
            


            



        End Sub

That's because "disabled" isn't a client-side property of the rendered control. It's a server-side property that makes no sense in the browser.

There isn't a way to "disable" a hyperlink, per se. What you can do is define a hyperlink CSS class that "looks" disabled, and then you can change the "href" property to navigate back to the top of the page, rather than submitting the form or going off somewhere else. Server-side, you'll also have to turn off the auto-postback of that element.

So, here's some CSS and JavaScript to make the hyperlink appear disabled, and navigate to page top:

The CSS:

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

The JavaScript:

function disableHyperlink(linkID)
{
  var hlink = document.getElementById(linkID);
  if(!hlink)
    return;
    
  hlink.href = "#";
  hlink.className = "disabledHyperLink";
}

Your server code:

Private Sub DataGrid_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid.ItemCreated
            If (e.Item.ItemType = ListItemType.Pager) Then
                e.Item.Attributes.Add("onclick", "disableHyperlink(this.ID);")
                e.Item.autopostback = false
            End If
        End Sub

All code untested and subject to revision/debugging!

what about doing this

Private Sub DataGrid_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid.ItemCreated

            If (e.Item.ItemType = ListItemType.Pager) Then
                

                e.Item.Enabled=false;
                
            End If
            


            



        End Sub

Because that will cause the control not to be rendered at all. That wasn't the question. It was how to make it appear and act disabled. This makes sense... users understand a "disabled" control. They don't always understand a control that mysteriously vanishes!

Hello orange soda,

I don't get the idea of disabling the pager button to prevent mutiple click on the page postback. The purpose of the pager is to be able the users to move from page to page. There must be something wrong in your code that fire an event during the page postback.

Check out the datagrid I created.
http://www.myasp-net.com/directory/adminlogin.aspx

You can download this application for free at:
http://www.myasp-net.com

Dexter zafra

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.