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.
Related
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.
I would like to develop a custom Toolstrip control. The control would be like a ToolStrip but with the following features :
The textbox would be proceeded by a label
The textbox would have two buttons after it.
I guess to implement this then a user drawn control would be required. Does anyone know of any resources available on the web to get me started on this.
First you should compose your usercontrol with label, textbox and buttons, exposing all the necessary Properties.
Here's a MSDN WalkThrough for UserControls creation
Then, use this answer (or this MSDN example) to create the custom ToolStripItem, just replace the TrackBar with you custom control.
P.S.
If you don't want to create a ToolStripItem, but just a popup showing your custom control, you can use this other example, replacing the ListBox with your control.
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.
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.
I want to change a user created control based on content of the input inside of textbox tied to JS.
My user control has an attribute field titled "userInput" where I pass the content of the textbox.
My page looks like this:
The textbox has an autocompleteextender and a Javascript function runs when an item from the dropdown is selected.
How do I pass the selected value back to the server so that my ascx user control can be updated with the appropriate data. (corresponding to what is in the textbox)
Assume that updatepanels/scriptmanagers are set up correctly (they are :-) )
Assuming you have an update panel around your custom ascx. Set up a trigger on that update panel that comes from the TextChanged event of your text box then set AutoPostback = true on the textbox. On the server, you can subscribe to the text changed event of the text box and write the code there to change the contents of the user control.