假设:页面上有一个文本框,一个下拉列表,我们希望,点击一个Button,后台可以获取我们在文本框填入的值,下拉列表选中的值,至于怎么处理这些值,那是另外的事情,代码如下:
Button代码如下:
从Button定义的代码我们可以看到,获取参数的代码就是#{TextField3}.getValue(),下拉列表也一样:#{ComboBox3}.getValue()
通过handler,我们可以访问后台的C#函数:
这样,我们就可以无刷新通过Button,给后台传递参数了.
<ext:TextField
ID="TextField3"
runat="server"
FieldLabel="Company Name"
AllowBlank="false"
/>
<ext:ComboBox
ID="ComboBox3"
runat="server"
FieldLabel="# of Employees">
<Items>
<ext:ListItem Text="1-5" Value="0" />
<ext:ListItem Text="6-25" Value="1" />
<ext:ListItem Text="26-100" Value="2" />
<ext:ListItem Text="101+" Value="3" />
</Items>
</ext:ComboBox>
Button代码如下:
<Buttons>
<ext:Button runat="server" Text="Submit" Icon="Lightning">
<Listeners>
<Click Handler="Coolite.AjaxMethods.LogCompanyInfo(#{TextField3}.getValue(), #{ComboBox3}.getValue());" />
</Listeners>
</ext:Button>
</Buttons>
从Button定义的代码我们可以看到,获取参数的代码就是#{TextField3}.getValue(),下拉列表也一样:#{ComboBox3}.getValue()
通过handler,我们可以访问后台的C#函数:
[AjaxMethod]
public void LogCompanyInfo(string name, int count)
{
string template = string.Concat("<b>{0}</b> has approximately <b>{1}</b> employees.");
string[] employees = new string[4] { "1-5", "6-25", "26-100", "100+" };
this.Label3.Html = string.Format(template, name, employees[count]);
}
这样,我们就可以无刷新通过Button,给后台传递参数了.