override page PreInit inside Custom server control - c#

I have custom server control contains templatefield when an out button clicked the field disappear , when can I rebind the control (inside its class) supposed that Control.Page.OnInit+=new EventHandler(rebind()) doesn't do any things ?

just rebind the control OnLoad() will solve the problem.

Related

ajaxToolkit:AsyncFileUpload - Dynamic controls created in the AsyncFileUpload1_UploadComplete() is not rendering to page

I am using a ajaxToolkit:AsyncFileUpload that allows the user to upload a excel file. In the AsyncFileUpload1_UploadComplete() event, I am reading the excel data and creating excel structure using div and adding to the page. But these dynamically created controls are not being added to the page. I added a button in the updatepanel and checked. On button click event, I created same above controls. In this case, the controls are rendering to the page. The controls are not rendering in case of ajaxToolkit:AsyncFileUpload only. Can anybody please tell me what is the fix for this.
Add Button into UpdatePanel where you want to show new controls and make it invisible with css style.
In the AsyncFileUpload1_UploadComplete server-side method, save your data to Session state.
In the client-side OnClientUploadComplete event handler call __doPostBack function with hidden button's UniqueID first parameter value. Then make all stuff required to render dynamic content in that button's click handler.

Display label in custom control used on an ASP.Net aspx page?

I am using a Custom control in my aspx page. This custom control has a error message label. I need to display this label from the code behind on button click. How can i achieve this.
Button and custom control is in Update panel.
I assume that in the custom control you have the label you want to show and the button you have on the update panel outside the custom control.
If so, you should create a public method in your Custom control, something like public void ShowError(string message) and when you do the button click you call this method passing the text to display. In the method implementation inside the custom control you will assign the message text to the label and display the label if not visible. This should actually work either you use an update panel or not as long as both button and custom control are at the same time outside or inside the UpdatePanel but not one in and the other out.

Dynamics controls lost on postback

This old chestnut again.
My page is constructed as follows; I have a dropdownlist which is databound on first load. When the user selects a value from this, a postback is performed which then databinds a repeater control.
The ItemTemplate of this repeater control contains a placeholder control. In code behind in the ItemDataBound event of the repeater, I am adding two controls dynamically to this placeholder, a hiddenfield and a checkbox.
When the user clicks the save button, I then want to iterate over all those dynamically created hiddenfields and checkboxes and determine their values. However when the user clicks the save button, those controls no longer exist as shown in the page trace.
I know this is a lifecycle issue and the articles I've seen on this suggest using Init methods to dynamically create your controls but I can't because of the way my page works, e.g. the repeater control only appears and binds after a value is chosen from the dropdownlist.
What do I need to do to maintain the dynamic controls through the postback caused by clicking on the save button?
The problem is when you hit the save button probabily you dont re-bind the repeater and the controls you have added at run time withint the ItemDataBound event are not longer available(because they don't exist anymore)
Why don't you add those control at design time using the Eval function the set up the value of the hidden field?
You just don't create them dynamically just on the on selection change of the drop-down set visibility true or false for the repeater that will solve your problem.on post back you have to again create those control as they are Dynamically created.

Triggering UpdatePanel on a button contained within a UserControl situated on the webpage

I would like an UpdatPanel to update it's content once a button is clicked - this button is contained within a UserControl placed on the webpage.
However, I cannot just simply reference it using the AsyncPostBackTrigger's ControlID property, because the button is not situated directly on the webpage.
Is there any way to reference it to the AsyncPostBackTrigger?
Use RegisterAsyncPostbackControl, e.g. if you have a user control UserControl1 containing Button1 and your script manager is called ScriptManager1:
ScriptManager1.RegisterAsyncPostbackControl(UserControl1.FindControl("Button1"));
Edit:
This will refresh all update panels, except panels that have their property set to conditional. For these panels you need to call UpdatePanel.Update(); in the code for the button.
Does the user control expose the button as a child control? If not can it? If not then you can use FindControl on the user control to find the inner button.

How can i create a ModalPopupExtender control dynamically from a server control?

I have a composite server control that does quiet a number of things; one of which is to display a ModalPopup OnClick of a dynamically generated HtmlAnchor control.
I need to create this ModalPopupExtender control dynamically in my server control and trigger it from within.
I have been able to create it and trigger it from a button created at design time but not at runtime. This is as a result of the ID assign to the link is always not found by the ModalPopupExtender control.
I have tried assigning a static ID but no success. Can anyone help?
I figured it out. All i needed to do was recreate the HtmlAnchor control in the overridden CreateChildControls method on postback.
Thanks David for you concern.

Categories