Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

linkbutton posts back when disabled

Status
Not open for further replies.

rotsey

Programmer
Nov 23, 2004
135
AU
Hi,

I have linkbutton that I disable by setting the disabled property.

FOr some reason when I click the button when grayed it still posts back.

Is this correct behaviour?

rotsey
 
I imagine it's not the way it's supposed to work, and I can't duplicate it. Can you give more details?
 
well I declare like this

<td width="70"><asp:linkbutton id="lnkUpdate" onclick="lnkUpdate_CLick" Font-Bold="True" Font-Underline="False" Font-Size="9pt" Font-Name="verdana" ForeColor="white" Runat="server" text="Update"></asp:linkbutton></td>

I am using javascript to validate on the click of this button and I want to set the disabled property in js and also server side so I initialise as below

CType(pg.FindControl("lnkUpdate"), LinkButton).Attributes("disabled") = "disabled"


And in client side js script I do this at another point

...
lnk = document.getElementById('lnkUpdate');
lnk.disabled=false;
...

So when it is disabled and I click on it it postsback.

Does this make sense?

rotsey
 
Couldn't you set lnkUpdate.AutoPostBack = False when you set the button to be disabled?
 
yeah but how would I set it back to postback in javascript when another button is clicked that uses javascript.
 
I would call an asp.net sub instead of the javascript, use registerclientscriptblock for the javascript and set the link button's autopostback = false.
 
so are you saying this is normal behaviour?
 
Does it make any difference if you set the Enabled property of the link button istelf rather than using FindControl and setting it's disabled attribute? e.g.
Code:
lnkUpdate.Enabled = False

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
yes it does. It works.

If I look at the source it seems that the href property is not set when do that ie

lnkUpdate.enabled = False

So when I try to set the disabled property in js I am not removing the href.

Maybe I should, you think??
 
If it works then yes although you will have to create a way of adding it back in though.

If you are simply enabling/disabling a linkbutton though maybe you should consider only doing it server side and having it postback to set the Enabled property. Posting back isn't a bad thing if it is only setting a property and will be quite quick.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top