使用Ext.net中的存储过程添加表单
本文关键字:存储过程 添加 表单 Ext net 使用 | 更新日期: 2023-09-27 18:18:07
我使用ext.net有问题。我是ext.net的新手,我不能像以前在。net框架中那样使用add存储过程。
这是我的asp代码:<ext:Panel ID="Panel1" runat="server" Title="Add Customer" PaddingSummary="5px 5px 0"
Width="790px" Frame="true" ButtonAlign="Center" Layout="Form">
<Items>
<ext:TextField ID="name" runat="server" FieldLabel="First Name" AllowBlank="false"
AnchorHorizontal="100%" />
<ext:TextField ID="surname" runat="server" FieldLabel="Last Name" AllowBlank="false"
AnchorHorizontal="100%" />
<ext:TextField ID="tcno" runat="server" FieldLabel="Citizenship Number" AnchorHorizontal="100%" />
<ext:TextField ID="mphone" runat="server" FieldLabel="Mobile Phone" AnchorHorizontal="100%" />
<ext:TextField ID="hphone" runat="server" FieldLabel="Home Phone" AnchorHorizontal="100%" />
<ext:TextField ID="wphone" runat="server" FieldLabel="Work Phone" AnchorHorizontal="100%" />
<ext:TextField ID="haddress" runat="server" FieldLabel="Home Adress" AnchorHorizontal="100%" />
<ext:TextField ID="waddress" runat="server" FieldLabel="Work Adress" AnchorHorizontal="100%" />
<ext:TextField ID="email" runat="server" FieldLabel="Email" Vtype="email" AnchorHorizontal="100%" />
</Items>
<Buttons>
<ext:Button ID="Button1" runat="server" Text="Submit">
<Listeners>
<Click Handler="Ext.net.DirectMethods.addClient();" />
</Listeners>
</ext:Button>
<ext:Button ID="Button2" runat="server" Text="Cancel"/>
</Buttons>
</ext:Panel>
和。cs文件是:
protected void Page_Load(object sender, EventArgs e)
{
}
[DirectMethod]
public void addClient()
{
SqlConnection myConnection;
SqlCommand myCommand;
string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["SiyahBayrakConnectionString"].ConnectionString;
myConnection = new SqlConnection(strConn);
myConnection.Open();
myCommand = new SqlCommand("addClient", myConnection);
myCommand.CommandType = System.Data.CommandType.StoredProcedure;
myCommand.Parameters.AddWithValue("@name", this.name);
myCommand.Parameters.AddWithValue("@surName", this.surname);
myCommand.Parameters.AddWithValue("@tcNo", this.tcno);
myCommand.Parameters.AddWithValue("@mobilePhone", this.mphone);
myCommand.Parameters.AddWithValue("@homePhone", this.hphone);
myCommand.Parameters.AddWithValue("@workPhone", this.wphone);
myCommand.Parameters.AddWithValue("@homeAddress", this.haddress);
myCommand.Parameters.AddWithValue("@workAddress", this.waddress);
myCommand.Parameters.AddWithValue("@email", this.email);
}
我的存储过程正在工作,但添加函数不工作。点击提交后,没有任何事情发生,数据库中也没有任何内容。有什么问题吗?
如果您只想从按钮单击事件调用方法,我倾向于使用以下语法:
<ext:Button .../>
<DirectEvents>
<Click OnEvent="addClient"/>
</DirectEvents>
</ext:Button>
处理程序用于当你想使用JavaScript方法基于你的按钮点击,尝试DirectEvents触发一个Ajax请求到服务器端方法。
检查你的语法,试试下面这个而不是Ext.net.DirectMethods.addClient();
它们实际上是相同的东西,但我不确定它是否可更改取决于您使用ext.net的版本。
但在我看来,你的代码是正确的,问题与ext.net无关。