Adding PostBackTriggers And AsyncPostBackTriggers To UpdatePanel For Dynamically-generated Grandchild Controls?
Jan 20, 2011
I have a page with a ScriptManager, a generic HTML drop-down list (<select>), and an UpdatePanel. The UpdatePanel contains a PlaceHolder (for now). During Page_Load, a number of user controls are added to the PlaceHolder (really, it's several instances of the same user control). The number to add is not known until the page loads, so they do need to be loaded dynamically. The drop-down list is populated with the same number of menu items, and there is javascript on the page also (using jQuery) to show only one of the controls at a time depending on the state of the drop-down list.
Each user control has two buttons that should generate an asynchronous postback, a drop-down list that should generate an asynchronous postback on a change in selected value, and a button that should generate a synchronous postback. If I was not generating the controls dynamically, and if there was only one control, the structure would be something like:
[code]....
Of course, all the controls inside the ContentTemplate would actually be part of each user control.
Adding the triggers on the server side does not seem to work because no ControlID seems to the UpdatePanel find the relevant controls. I can use either the control's ID or the control's UniqueID, and it does not work, and I get an error along the lines of
A control with ID 'ctl00$ContentPlaceHolder1$ctl01$asyncButton1' could not be found for the trigger in UpdatePanel 'myUpdatePanel'.
So, I wonder if I need to register the triggers in the client instead using ASP.NET Ajax. I found this page that basically explains how. However, I do not know how to get the EventName taken into consideration. The examples I have seen so far have merely been adding button clicks, but I don't know how to handle the SelectedIndexChanged event from the DropDownList.
Are there examples out there I have missed? It doesn't , of course, that the method in the link I gave appears to be "unofficial," so I don't see any MSDN documents on the subject.
I am stuck in chart controls...Here is my prob... There is a ListBox containing some items...when user selects multiple items from the list box I want to generate a dynamic table with the number of columns same as that of the number items selected in the listbox. And for each selected item I want to show a seperate chart in the columns...Currently I want the same chart control for every selected item (i.e. a static hard coded chart that i will replace later by dynamic values)....I am using a method that draws a chart control using a sample dataset... I am calling it each time when a new column is created..Also the DrawChart method executes for the first column only and throws an index out of range exception! after the first execution...my code is not working...here
Here is what I am trying to do. I have a page with two link buttons and an updatepanel (the two linkbuttons trigger the updatepanel). I have two usercontrols which have labels with same ID's. When I click the first link button, I add the first usercontrol to the updatepanel and set the label value to datetime.now
when i click the second link button i add the second usercontrol but i see that the value of the label from the first control is set in the label in second user control. if the id's are different there is no problem - but in my case the usercontrols are being developed by different teams and I am integrating them in the way i mentioned - so they may have same ids.
I have gone through several posts on this forum about adding a linkbutton to an updatepanel dynamically. A lot of them say just give it a unique ID and some say you have to register add an AsyncPostBackTrigger to the triggers collection. I have tried both and neither work. I have this simple test that I created - the code is below - there is nothing else in this project but the code you see so I know nothing else is interfering with it.
I have also seem people complaining that the linkbutton causes the entire page to postback - in my case nothing happens... I have seen people talk about having to add the triggers on the page init however I can't do that - I am dynamically creating menus based on a selection in a listbox... (not in this simple test but in a larger project) I am using Visual web developer express 2010 if that makes any difference.
I'm displaying a table based on query results, and each record has a dynamically generated dropdownlist and submit button (and other controls, but this is simplified). That part works fine, but how do I reference the controls in a function? Here is the code I've tried. Create the controls:
[Code]....
Reference the control values (hopefully):
[Code]....
The function SubmitAction_Click fires when I click the Post button, so that part works. I just can't figure out how to reference the selected value of the dropdownlist. You can see that I'm explicitly giving the DDL a unique ID (DS_RecordID). I'm guessing I have to use FindControl to reference it, but I don't know how to format the code.
Let's say I have a booking form which is divided into 3 separate views in a multi view.
View 1: "How many people do you want to book for?" And then just a text box
View 2: "Please enter the details for each of the people" And then a series of dynamically generated text boxes - the number of boxes is determined by the value in the textbox in view 1 (e.g. if the users enters "3" into the text box, there will be 3 series of text boxes like "Details of person 1: First Name <textbox> Last Name <textbox>, Details of person 2: First Name<textbox etc..."
View 3: "Please review and confirm the details are correct:" Displays data entered in view 2.
Here's the difficult part - In order to generate the controls in view 2, I need to know the value of the text box in view 1. This value isn't available during Page_Init as viewstate has not yet been written. But - need to build the controls during Page_Innit. So - I thought why not try to grab the value of the textbox using Request.Form[Texbox1.ClientID]; - this is fine when moving from view1 to view2 but remember - I need to recreate these controls again if the user moves back to view1 or forward to view3 (it is a requirement that the user can move backwards and forwards between the views).
So - User enters value in Textbox in View1, hits the "Next button", we request that value using Request.Form and generate a series of controls dynamically. Then the user clicks "Next" again and moves to view 3 where we would like to show a summary of what they entered. But - we cant because those controls dont exist as we could not create them because the value of textbox1 is not available during Page_Init and we can't use Request.Form as the textbox isn't now part of request.form because we came from view2, not view1.
I can't figure out how to dynamically create these controls and then recreate them during page_innit on each postback so we retain any values the user might have entered.
i use the below code to dynamically generate two dropdowns and a text box in my MVC project.countValidate is used to concatenate and produce controls with postfix 1 ,2,3 etc.now i need to access the Criteria? series dropdown and check their values and according to the values received on changing the Criteria dropdown the value textbox must be disabled or enabled, in javascript.
I have a grid and on each row of grid i generate a radiobuttonlist with 2 items dynamically in rowdatabound. On the save button event i want to access the data of the row and save the data in DB with which ever radio button is selected.I tried different things but all in vain. I tried to use hidden field so that whenever any radio button is selected in a row then in javascript i will update the hidden field but user can select multiple rows so this is not a good solution.
Here is my code of dynamic radio button list generation in rowdatabound event.
I am generating barcode image dynamically on button click .
The image is display on the asp image control, now I want to save that image in database
string barCode = txt_ID.Text; using (Bitmap bitMap = new Bitmap(barCode.Length * 40, 80)) { using (Graphics graphics = Graphics.FromImage(bitMap)) { Font oFont = new Font("IDAutomationHC39M", 16); PointF point = new PointF(2f, 2f);
I'm trying to check dynamically generated "checkbox" value inside Listview.
I can reference non-dynamic checkboxes exact in same location (index) inside Listview using "e.Item.FindControl", however I can't reference dynamic checkboxes.
I have a gridview each line has 4 linkbuttons - Edit , Update , Cancel , Delete and a few columns with data...For example TeamName and TeamEmail, and a hidden column that contains a validator (for ease of validating controls that are found on the same row , same naming container)
When Edit button is Clicked , the specific line goes into editing mode , Texboxes are created for TeamName and for TeamEmail .
I create dinamically (code behind ) a new textbox that reads the value from the TeamEmail textbox , i give it a new id (let's say "Email") , add that email to the controltovalidate property of my validator , and call the validate() method of the validator.
Everything works fine when i modify the value in a worng format , the validator err message appears , when i modify the TeamEmail value to a good email format , the validator property isvalid becomes true , and the update is running , but my textbox is empty :( updating the TeamEmail value to null.
This is some bad code but hope you understand what i meant :
i hav a dyanmically generated gridview with autogenerated columns = true.. i want to change the width of a column of a grid... i tried to do it in row databound event as...
e.Row.Cells[1].Width = Unit.Pixel(300);
but it doesnt work... and since d columns are genrated dynamically i cant set d width as grd.columns[0].width =...
i have just found that i cant create postback triggers on the fly (i had a function that runs onclick that creates buttons and postback triggers)
so i need an alternative or a method to achieve this
what happens is onclick of a button, updatepanel1 is updateded and depending on what button you click in panel1 more buttons are added, these buttons that are added also have an oncllick event that should update a wysiwyg in panel2 with content
heres my code below, if anyone has any ideas or knows of other methods to get this to work it would be great
i'm worried about doing this since my changes will be overwritten when the dbml file is auto generated again (as they often are).
i'm thinking of doing a partial class and writing out the same properties to annotate them, but worried that it will complain about duplicates, and the reason i can't even experiment brings me to the second part of my questions...
... that, the expandable arrow on my dbml file listing is missing, right clicking and selecting "View Code" just displays an empty partial class as below...
Partial Class FPDataContext End Class
I'm using VS2010 RC and am just developing an MVC 2.0 app where i want to be able to use the UI Annotations such as [UIHint("RelativeDateTime")]
edit:
here is my VB version edit as an example...
Imports System.ComponentModel.DataAnnotations <MetadataType(GetType(CommentMetaData))> _ Partial Public Class Comment End Class Public Class CommentMetaData <UIHint("PostedSince")> _ Public Property DateAdded() As DateTime End Class
i have a lable a textbox, and two buttons(+ and - button) on my asp.net page.
so when i click on the plus button it should add the the whole collection of controls to the page(i.e. lable, textbox and two buttons). And when i click on minus button it should remove the collection.
This should go on.meaning whenever i click on any plus button the control collection should get added to the page.
I am wondering what will be the best approach to do it.
I create a gridview dynamically to fit the contents of a datatable...This form will have other dataatbles thrown at it but for the moment I am only working on one to work out the details of the process.I will post all my code below...the problem is this. The code successfully geenrates the gridview the way I want however...whenever I select a row all the cells including the header cells dissapears [code]...
I have a table witch i programmatically fill with(multiple) IDs in the first column, options in the second and checkboxes in the third. The table is in a View as it is part of a wizard and is filled on view_Activate.
How can i get the checked property of the checkboxes when i pass to the next view? When i try to do that on view_Deactivate the table is already 0 rows...
I know i can use i checkboxlist(... whose properties i can get on view_Deactivate) but i'd rather use a table as it is easier to layout as i want it(header, columns, alignment,...).
I have a hyper link control and I set the NavigateURL and the ImageURL property at runtime. I also need to set the class of the image tag that it generates but I cannot figure out how I can do that. The solution mentioned here [URL] does not work because the image url is hard coded.