Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue adding multiple controls to placeholder returned by function
    primarykey
    data
    text
    <p>I have a function that creates multiple controls. Mainly input fields and an imagebutton with dynamic data for an Amazon payment button. </p> <p>How can I add these controls to a placeholder so they are rendered on the page?</p> <p>I tried creating a placeholder inside the function, adding controls and returning the placeholder. </p> <pre><code>plhCart = returnedPlaceHolder() </code></pre> <p>The controls did not render however when do a plhCart.Controls.Count the value was correct. </p> <p>This is the function creating the controls and adding them to a placeholder object:</p> <pre><code> Protected Function GetPayNowWidgetForm(ByVal formHiddenInputs As SortedDictionary(Of [String], [String])) As PlaceHolder Dim payButton As New ImageButton Dim plhForm As New PlaceHolder Dim counter As Integer = 1 payButton.ID = "imgPayButton" payButton.PostBackUrl = "https://authorize.payments-sandbox.amazon.com/pba/paypipeline" payButton.ImageUrl = "https://authorize.payments-sandbox.amazon.com/pba/images/GMPayNowWithAmazon.png" plhForm.Controls.Add(payButton) ' Add the Key/Value pairs from formHiddenInputs For Each kvp As KeyValuePair(Of [String], [String]) In formHiddenInputs Dim hiddenField As HtmlControl = New HtmlControls.HtmlInputHidden ' Dim hiddenField As New HiddenField hiddenField.Attributes.Add("name", kvp.Key) hiddenField.Attributes.Add("value", kvp.Value) plhForm.Controls.Add(hiddenField) counter += 1 Next Return plhForm End Function </code></pre> <p>I am now using Steve Temple's suggestion and adding this returned placeholder to the placeholder on my page using </p> <pre><code>plhCart.Controls.Add(GetPayNowWidgetForm(...)) </code></pre> <p>This is working fine, and probably better than what I came up with last night. My original solution was to create the controls and returning them as a system.array. Then looping through the array to add each control to the placeholder. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload