Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4270648
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:20:06+00:00 2026-05-21T07:20:06+00:00

I used Firebug to verify, and my callback is firing successfully. In the Post

  • 0

I used Firebug to verify, and my callback is firing successfully. In the “Post” portion, it shows that my TextBox (rather, the HTML that was rendered for my textbox) is successfully submitting its form value (whatever was entered in the textbox). However, on the server side, the value isn’t being restored into the newly created TextBox — even though everything I’m recreating has the same ID as it originally did. Furthermore I checked the Page.Request.Form collection (see: getControlAsHtml()) and none of the things I tried returned my value. Here is the code, appreciate any help.

Summary

my goal is to perform a callback (currently working) and restore the value of my TextBox from the posted back form values (not working). Some (working) code has been omitted for brevity.

public class CreateForm : WebPart, ICallbackEventHandler
{
    public string callbackData = "";
    public DropDownList list = new DropDownList();
    public Panel p = new Panel();

    public virtual string GetCallbackResult()
    {
        return callbackData;
    }

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

            //The DropDownList is created here in my real code, but was omitted
            //because it is working as expected.
            //At the moment, all the DDL does is cause a callback to occur.

        p.ID = "theForm";

        if (!Page.IsPostBack) 
        {
            MyForm MyForm = new MyForm();
            MyForm.ID = "currentForm";
            p.Controls.Add(MyForm);
        }

        Controls.Add(p);  
    }

    /*
     * The eventArgument field is parsed to get the desired command.
     * Valid commands:
     * 1) send - Indicates the user has clicked the 'send' button. 
     * 2) display - Indicates the user wants to change the form
     *              currently displayed.
     *    A drop down box is used to let the user choose the form. 
     */
    public virtual void RaiseCallbackEvent(string eventArgument)
    {
                if (eventArgument.StartsWith("display"))
            {
                //always index 0 for testing. 
                callbackData = CreateFormByType(0);
                }
    }

    public string CreateFormByType(int index)
    {
        MyForm test = null;

        switch (index)
        {
            case 0:
                test = new MyForm();
                break;
        }

        if (test != null)
        {
            test.ID = "currentForm";
            p.Controls.Add(test);
        }

        return test != null ? test.getControlAsHtml() : null;
    }

}

public class MyForm : Control
{
    public Label label = new Label();
    public TextBox textboxForLabel = new TextBox();

    protected override void OnInit(EventArgs e)
    {
            base.OnInit(e);

        textboxForLabel.ID = "textboxForLabel";
        label.AssociatedControlID = "textboxForLabel";
        label.Text = "textboxForLabel: ";

        this.Controls.Add(label);
        this.Controls.Add(textboxForLabel);
    }

    public virtual string getControlAsHtml()
    {
            //How come all 3 of these don't return the expected value?
        string s = Page.Request.Form[textboxForLabel.ID];
        string t = Page.Request.Form[textboxForLabel.ClientID];
        textboxForLabel.Text = (string)Page.Request.Form["textboxForLabel"];

        StringBuilder sb = new StringBuilder();
        using (StringWriter sw = new StringWriter(sb))
        {
            using (HtmlTextWriter textWriter = new HtmlTextWriter(sw))
            {
                this.RenderControl(textWriter);
            }
        }
        return sb.ToString();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:20:07+00:00Added an answer on May 21, 2026 at 7:20 am

    So Controls.Add() isn’t an innocent
    addition to a simple collection. It
    immediately has an impact on the
    control being added, as it “grows up”
    at an accelerated pace. But the steps
    through which the control is fast
    forwarded don’t completely correspond
    to all of the events available on the
    page. The only events eligible for
    this process are (in order): Init,
    LoadViewState, Load, PreRender.

    According to that article segment, which I found at InfinitiesLoop, the reason that the TextBox isn’t getting updated data is actually because when a control is added to the control tree, the control catches up to the other controls in the control lifecycle. But the LoadPostData method is not eligible for this catch up process. In other words, the data is available in the Request.Form collection but the LoadPostData() method is never called, since the ‘MyForm’ control is added from the RaiseCallbackEvent method — which is later in the lifecycle than the LoadPostData event. So calling RegisterRequiresPostBack might work (if it forces LoadPostData to be called) but not for the reason that Priyank indicated in the comments.

    I should also add that it is necessary to do the following from the Javascript code that causes the Ajax callback to occur:

    __theFormPostData = ""; WebForm_InitCallback();
    

    The reasoning behind that is that it clears the form which is not up to date and then updates it (by calling InitCallback()) before actually performing the callback request.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I notice in several API's, that you may create a struct which is used
I am using a 3rd-party rotator object, which is providing a smooth, random rotation
I want to get the header of a selected tab-item of a tab-control and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.