1、动态生成控件,无法取得控件的值:
protected void Page_Init(object sender, EventArgs e)
{
ComboBox cmbTest = new ComboBox();
cmbTest.ID = "cmbTest";
InitBooleanDrop(cmbTest);
cmbTest.DirectSelect += new ComponentDirectEvent.DirectEventHandler(cmbTest_DirectSelect);
this.Page.Controls.Add(cmbTest);
}
private void InitBooleanDrop(ComboBox cmb)
{
ListItem item = new ListItem();
item.Text = "---请选择---";
item.Value = "0";
cmb.Items.Add(item);
item = new ListItem();
item.Text = "Y";
item.Value = "1";
cmb.Items.Add(item);
item = new ListItem();
item.Text = "N";
item.Value = "2";
cmb.Items.Add(item);
cmb.SelectedItem.Text = cmb.Items[0].Text;
}
//不能取得选择的值
void cmbTest_DirectSelect(object sender, DirectEventArgs e)
{
ComboBox cmb = (ComboBox)sender;
X.Msg.Alert(cmb.SelectedItem.Text, cmb.SelectedItem.Value).Show();
}
测试了好久,其实问题就出在这句:
this.Page.Controls.Add(cmbTest);
将其改为以下这句就好了:
this.form1.Controls.Add(cmbTest);
2、在代码中控制显示和隐藏控件:
不能直接使用Visible属性来控制,应使用Hide()和Show()两个方法来控制,具体可以参考:
http://forums.ext.net/showthread.php?13114&p=54033&viewfull=1#post54033
http://forums.ext.net/showthread.php?13114&p=54033&viewfull=1#post54033 Visible and Hidden are not the same. If Visible=false then a widget is not rendered at all (it is absent on client side) therefore we cannot change visibility on client side.
You have to rerender the widget after set Visible=true during DirectEvent Widget1.Render(); If Hidden=true then the widget is rendered but hidden in the browser, you can easly to control visiblilty in the client side by Hidden
property during DirectEvent
3、在创建复合控件时,出现“The control with ID '控件ID' not found”:
原因是由于控件没有在“CreateChildControls”方法中创建;
4、GridPanel无法获得选择的行:
原因:设置Store中Model对象的IDProperty属性为字段名即可。
5、用Ext.Net在创建自定义控件时,出现“Token is not unique”的问题:
“/”应用程序中的服务器错误。 -------------------------------------------------------------------------------- Token is not unique ------------------- ID = _ClientInit TagName = anchor Match = <#:anchor id="_ClientInit" /> 说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: Transformer.NET.TokenNotUniqueException: Token is not unique ------------------- ID = _ClientInit TagName = anchor Match = <#:anchor id="_ClientInit" /> 源错误: 执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。 堆栈跟踪: [TokenNotUniqueException: Token is not unique ------------------- ID = _ClientInit TagName = anchor Match = <#:anchor id="_ClientInit" /> ] Transformer.NET.Token.ParseAnchors() +508 Transformer.NET.TextTransformer.Parse(List`1 tokensType, Dictionary`2 variables) +1063 Transformer.NET.TextTransformer.Transform(List`1 tokensType, Dictionary`2 variables) +42 Transformer.NET.TextTransformer.Transform(List`1 tokensType) +41 Transformer.NET.TextTransformer.Transform() +53 Ext.Net.ExtNetTransformer.Transform(String text) +210 Ext.Net.InitScriptFilter.Transform() +50 Ext.Net.InitScriptFilter.Flush() +74 System.Web.HttpWriter.Filter(Boolean finalFiltering) +8782518 System.Web.HttpResponse.FilterOutput() +82 System.Web.CallFilterExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +47 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75