Nested controls in LinkButton not clickable - asp.net

I am working on a Composite custom control.
In said control, I am inheriting from LinkButton. In this LinkButton, I am nesting a Label Control and 5 Image controls.
I am able to render everything properly, and I´ve got the btton doing its on click events and everything, however, there´s a slight problem:
Once the button has rendered, the nested controls appear above the linkbutton, so that the linkbutton is not clickable where these added controls are...
What I want to know, is there a way to place them behind the linkbutton or something? So that the button is still clickable?
Thanks in advance!

I would highly recommend inheriting from CompositeControl, as that is the base class meant for situations like this. Then you can render out the linkbutton at the point you want, and add it to the inner control collection.

Related

Visible Property of ASP.Net Control not working

I have a radiobutton list and three placeholders in my page, out of which the radiobutton list,first and third placeholder are within updatepanel, second placeholder is not within updatepanel.
When radiobutton list selectionindex is changed, I want all three placeholders invisible. Placeholder2.visible=false code executes but still Placeholder2 is visible.
How to resolve this.
Thanks,
Viknesh.A
You should put all your placeholders in update panel on reload the page when the radio button hits (full post back) by setting AutoPostBack="true"
You should understand that by default changin radio button on a client only affects client html, so you need to pass that info to server.
Another option is to have client onclick for radiobutton and write your custom javascript function to hide your second placeholder, but don't forget to manage that situation on the server as well, when postback (either ajax or not) will occur.
Move Placeholder2 inside the UpdatePanel.
Or don't use an UpdatePanel at all.
Or use JavaScript to hide it, instead of server-side code.

How can I make a repeater field editable?

I have a page with a repeater.. I have to make some fields of this one editable. I don't see how I can transform the repeater label into a textbox.. Can I use jquery to do that?
Have somebody make this kind of manipulation?
Thanks..
The Repeater control does not have an EditTemplate like many of the other data controls.
I would suggest having the edit fields either in a hidden Placeholder, then show this when clicking an edit button. This would involve the page posting back and then you having to show/hide the relevant parts in the ItemCommand handler.
Another way would be do add the edit fields/textboxs in a Panel control, then hide this through display: none;. Then you can change this to display: block; with some javascript. This will avoid the page PostBack.
This can be done in a Repeater, but a DataList control is more straightforward and is just as easy to use. There's an MSDN article on doing it in a Datalist control with full source code here: http://msdn.microsoft.com/en-us/library/bf5211wb(v=vs.71).aspx
Converting a repeater to a DataList is a much easier approach than having editable items in a Repeater.
HOWEVER
to answer your question directly, there IS a Codeproject sample here: http://www.codeproject.com/KB/aspnet/EditableRepeater.aspx
that shows how to use a Repeater with full edit functionality (including adding and deleting items).
To see the relevant code in the CodePlex article, search for the text "EditIndex". The relevant code-behind is always a few lines above and/or below this keyword.
It depends on how you want to do this:
using standart control probably you need GridView.
You can define the template for repeater and put TextBox there, then
on postback you will need to find dynamically created controls and
also you will need to take care to keep ID's of these controls the
same on postbacks.
And the other thing - you can replace label with the textBox using
jQuery and then update value via Ajax reques.
You decide what you need :) Anyway it's a lot of samples in the internet.

button events in datalists

I have a datalist and want to dynamically add buttons to it. I am using the OnItemCommand datalist event and setting the CommandName/ CommandArgument attributes of the button.
However I am having trouble with handling the button click - does not seem to fire.
It works when I declared a button on the aspx page, but not for buttons that are dynamically created.
I hope this makes sense, and any help would be great.
Thanks
You can only create dynamic controls on PreInit or Init if you want to handle associated events. Otherwise, on postback, they won't exist at the moment of event handling and because of that, your handler method won't be called.
Internet is full of resources about how to handle dynamic controls. Let me know if you need any reference.

ASP.NET Button vs Linkbutton Enabled="false" behavior

Why do ASP.NET LinkButton controls with OnClientClick attribute and disabled by setting Enabled="false" still render onclick event handler in HTML while Button controls don't?
It seems counter-intuitive. Since anchors can't really be disabled in browsers, it makes more sense not to attach an onclick event (and href attribute) if it has been set disabled on server-side.
Well I would agree that it doesn't server much purpose, but without changing the way the linkbutton renders with one of the many methods built into asp.net there really isn't anything you can do about it. Unless you want to conditionally handle clicks in clientside code and check element attributes. This is just the way it is currently implemented so when you need the functionality of a button that can be disabled it is best to stay way from linkbuttons or anchors entirely.
This really has little to do with asp.net.
A hyperlink button still fires the onclick event even when disabled. Bottom line: baked into HTML. (An input tag, when disabled, does not fire.)
Click Me!

ASP.net ACTK DragPanel Extender on PopupControlExtender with UpdatePanel does not drag after partial postback

I have a panel on an aspx page which contains an UpdatePanel.
This panel is wrapped with both a PopUpControl Extender as well as a DragPanel Extender.
Upon initial show everything works fine, the panel pops up and closes as expected and can be dragged around as well.
There is a linkbutton within the UpdatePanel which triggers a partial postback. I originally wanted to use an imagebutton but had a lot of trouble with that so ended up using the linkbutton which works.
Once the partial postback is complete I can no longer drag the panel around.
I would love to hear suggestions on how to fix this.
Has anyone else encountered this problem?
What did you do about it?
Do you know of any other way to accomplish this combination of features without employing other third party libraries?
Take a look at when the drag panel extender and popup control extender actually extend your panel.
Chances are those extenders work on an initialization event of the page. When the update panel fires and updates your page the original DOM element that was extended was replaced by the result of the update panel. Which means that you now have a control that is no longer extended.
I don't really know of an easy solution to this problem. What will probably work is if you can hook into an event after the update panel has updated the page and extend the panel again.

Resources