私はFirebugを使って検証し、私のコールバックは正常に起動しています。 「投稿」部分には、自分のテキストボックス(テキストボックス用にレンダリングされたHTML)がフォームの値(テキストボックスに入力されたもの)を正常に送信していることが表示されます。しかし、サーバー側では、新しく作成されたTextBoxに値が復元されていません。再作成したものすべてが元のIDと同じIDを持っています。さらに、私はPage.Request.Formコレクション(getControlAsHtml()を参照)をチェックしました。コードはありますが、何か助けていただければ幸いです。投稿されたバックフォームの値が読み込まれていませんか?
概要
私の目標は、(現在作業)コールバックを実行し、バック投稿フォーム値(動作していない)からの私のTextBoxの値を復元することです。一部の(作業中の)コードは簡潔にするため省略されています。
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();
}
}
タイトルに「ASP.NET C#」などのタグを重複しないでください。彼らは既にタグに入っています。 –
@Johnは指摘..ありがとう。今私はこの質問に答えるのを助け、私たちは親友になることができます。 :) – KyleM
いいえ、私はしません。私は答えを持っていない、または私はそれに答えるだろう。 –