weixin_33721344 2017-07-19 07:08 采纳率: 0%
浏览 54

在asp.net表单上应用AJAX

I have the following code for a Form in ASP.NET. I want to apply AJAX on it. How would I do this?

image of the form

In this form, I also have a gridview on the same page showing the entries which I make using form. I don't want the page to reload when I press save button.

<form id="form1" action="~/studentForm.aspx" runat="server">

        <div class="table-responsive form-group">

            <table class="table table-hover" style="width: 100%;" spellcheck="False">

                <tr>
                    <td class="auto-style12"><b>Name</b></td>
                    <td class="auto-style13">
                        <asp:TextBox ID="txtName" runat="server" class="form-control" Width="202px"></asp:TextBox>

                    </td>
                    <td>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtName" ErrorMessage="Enter Your Name " ForeColor="#CC0000" SetFocusOnError="True" Style="text-align: right; font-weight: 700; color: #FF0000" ToolTip="Enter Name" ValidationGroup="saveUser">Required</asp:RequiredFieldValidator>

                    </td>
                </tr>
                <tr>
                    <td class="auto-style12"><b>AGE</b></td>
                    <td class="auto-style13">
                        <asp:TextBox ID="txtAge" runat="server" class="auto-style14" Width="202"></asp:TextBox>
                    </td>
                    <td>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtAge" ErrorMessage="Enter Your Age" ForeColor="#CC0000" CssClass="auto-style2" SetFocusOnError="True" ToolTip="Enter Age" ValidationGroup="saveUser">Required</asp:RequiredFieldValidator>
                        <br />
                        <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="txtAge" ErrorMessage="Age Must Be Between 18 and 60" ForeColor="#CC0000" MaximumValue="60" MinimumValue="18" Style="text-align: right; font-weight: 700; color: #FF0000" ToolTip="Enter Age Between 18 and 60" Type="Integer" ValidationGroup="saveUser">Invalid Age</asp:RangeValidator>
                    </td>
                </tr>
                <tr>
                    <td class="auto-style12"><b>Department</b></td>
                    <td class="auto-style13">
                        <asp:DropDownList ID="ddlDepartment" runat="server" class="form-control btn btn-primary dropdown-toggle" Width="202px">
                            <asp:ListItem Value="-1">Select Departement</asp:ListItem>
                            <asp:ListItem>COMMERCE</asp:ListItem>
                            <asp:ListItem>LAW</asp:ListItem>
                            <asp:ListItem>IT</asp:ListItem>
                            <asp:ListItem>BBA</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                    <td>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="ddlDepartment" ErrorMessage="Enter Your Departement" ForeColor="#CC0000" InitialValue="-1" CssClass="auto-style2" SetFocusOnError="True" ToolTip="Select Drpartement" ValidationGroup="saveUser">Required</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td class="auto-style12"><b>Gender</b></td>
                    <td class="auto-style13">

                        <asp:RadioButton ID="rdBtnMale" runat="server" class="radio-inline" Checked="True" GroupName="gender" Text="Male" />
                        <asp:RadioButton ID="rdBtnFemale" runat="server" class="radio-inline" GroupName="gender" Text="Female" />
                    </td>
                    <td class="auto-style6"></td>
                </tr>


                <tr>
                    <td><b>Subjects</b></td>
                    <td>
                        <asp:CheckBoxList ID="CheckBoxList2" runat="server" RepeatDirection="Horizontal" Width="298px">
                            <asp:ListItem>Physics</asp:ListItem>
                            <asp:ListItem>Chemistry</asp:ListItem>
                            <asp:ListItem>Biology</asp:ListItem>
                        </asp:CheckBoxList>
                    </td>
                    <td></td>
                </tr>


                <tr>
                    <td class="auto-style12">
                        <asp:Button ID="btnSave" runat="server" class=" btn btn-success" OnClick="btnSave_Click" Text="Save" Width="105px" ValidationGroup="saveUser" />
                        <input id="btnReset" class="btn btn-warning" type="reset" value="Cancel" style="width: 105px" />

                    </td>
                    <td class="auto-style13">&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>
            </table>
        </div>

</div>
  • 写回答

1条回答 默认 最新

  • weixin_33727510 2017-07-19 07:13
    关注

    In Asp.Net you can use the Update Panel:

    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                   [your code here]
                </ContentTemplate>
            </asp:UpdatePanel>
    
        </div>
        </form>
    </body>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)