保存按钮没有任何响应

时间:2014-04-08 10:57:54

标签: c# asp.net ajax updatepanel cascadingdropdown

我将感谢您在我的案例中给予您的帮助和支持,因为我的注册论坛的保存按钮它没有工作我点击了多次但没有任何反应它假设将记录保存在数据库中并移动我到另一页但没有任何事情发生。

    public partial class Registration : System.Web.UI.Page
{


    string sc = ConfigurationManager.ConnectionStrings["BeravaConnectionString"].ConnectionString.ToString();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            DataTable countrycascd = new DataTable();
            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["BeravaConnectionString"].ConnectionString))


            {
                SqlDataAdapter adaptar = new SqlDataAdapter("select [countryID],[country] FROM [countr]", con);
                adaptar.Fill(countrycascd);

                countrdrdolst.DataSource = countrycascd;
                countrdrdolst.DataTextField = "country";
                countrdrdolst.DataValueField = "countryID";
                countrdrdolst.DataBind();
            }

            countrdrdolst.Items.Insert(0, new ListItem("select country", "0"));
        }
    }


    protected void btnSave_Click(object sender, EventArgs e)
    {



        SqlConnection cn = new SqlConnection(sc);
        SqlCommand cmd = new SqlCommand();

        string sqlstatment = "INSERT INTO UserInfo (UID, FN, LN, Password, RePass, Email,Country, State,City, Post, Img) VALUES (@UID,@FN,@LN,@Password,@RePass,@Email,@Country,@State,@City,@Post,@Img)";

        cmd.Connection = cn;
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = sqlstatment;

        //Insert the parameters first
        cmd.Parameters.AddWithValue("@UID", UsrNme.Text);
        cmd.Parameters.AddWithValue("@FN", fnbox.Text);
        cmd.Parameters.AddWithValue("@LN", lnamebox.Text);
        cmd.Parameters.AddWithValue("@Password", passtxtbx1.Text);
        cmd.Parameters.AddWithValue("@RePass", passtxtbx2.Text);
        cmd.Parameters.AddWithValue("@Email", emailbox.Text);
        cmd.Parameters.AddWithValue("@Country", countrdrdolst.Text);
        cmd.Parameters.AddWithValue("@State", statedrdolst.Text);
        cmd.Parameters.AddWithValue("@City", citiesdrdolst.Text);
        cmd.Parameters.AddWithValue("@Post", postbox.Text);

        //Check if there's a file or not
        if (FileUpload1.HasFile && FileUpload1.PostedFile.ContentLength > 0)
        {
            FileUpload1.SaveAs(Server.MapPath("~/images/users/" + FileUpload1.FileName));
            cmd.Parameters.AddWithValue("@Img", FileUpload1.FileName);
        }
        else
        {
            //Must add the paramater value to any value or DBNull.Value
            cmd.Parameters.AddWithValue("@Img", "");
        }

        //Open the connection and execute the command
        cn.Open();
        cmd.ExecuteNonQuery();
        //Close the connection
        cn.Close();
        Response.Redirect("User panel.aspx");


    }




    protected void countrdrdolst_SelectedIndexChanged(object sender, EventArgs e)
    {

        int countryID = Convert.ToInt32(countrdrdolst.SelectedValue);
        DataTable StateDT = new DataTable();
        using (SqlConnection con2 = new SqlConnection(ConfigurationManager.ConnectionStrings["BeravaConnectionString"].ConnectionString))
        {
            SqlDataAdapter adaptar = new SqlDataAdapter("Select [StateID],[State] FROM [State] WHERE [countryID] = " + countryID, con2);

            adaptar.Fill(StateDT);

            statedrdolst.DataSource = StateDT;
            statedrdolst.DataTextField = "State";
            statedrdolst.DataValueField = "StateID";
            statedrdolst.DataBind();
        }

        statedrdolst.Items.Insert(0, new ListItem("select State", "0"));


    }

    protected void statedrdolst_SelectedIndexChanged(object sender, EventArgs e)
    {

        int StateID = Convert.ToInt32(statedrdolst.SelectedValue);
        DataTable City = new DataTable();
        using (SqlConnection con3 = new SqlConnection(ConfigurationManager.ConnectionStrings["BeravaConnectionString"].ConnectionString))
        {
            SqlDataAdapter adaptar = new SqlDataAdapter("select [CityID],[City] FROM [Cities] WHERE [StateID] = " + StateID, con3);
            adaptar.Fill(City);

            citiesdrdolst.DataSource = City;
            citiesdrdolst.DataTextField = "City";
            citiesdrdolst.DataValueField = "CityID";
            citiesdrdolst.DataBind();
        }

        citiesdrdolst.Items.Insert(0, new ListItem("select City", "0"));
    }

    protected void citiesdrdolst_SelectedIndexChanged(object sender, EventArgs e)
    {

    }


}
}










<%@ Page Title="" Language="C#" MasterPageFile="~/SVM.Master" AutoEventWireup="true" CodeBehind="Registration.aspx.cs" Inherits="beravoSV.Registration" %>

<style type="text/css">
.style5
{
    width: 191px;
    color:#606060;
}
    .style6
    {
        float: left;
        height: 25px;
        color: White;
        font-size: small;
        padding-left: 20px;
        padding-right: 9px;
        background-color: #a340bf;
    }
</style>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>


<div class="banner728">
    <asp:Image ID="Image1" runat="server" 
        ImageUrl="~/images/general/bann72890.png" />
</div>
<div class="space">
</div>
<div class="style6">
    <strong style="font-size: medium">Registre New User</strong></div>
<br />
<br />
<br />
<br />
<table style="width: 69%; height: 338px;" align="center">


   <tr>

   <td class="style5"> &nbsp; Användarnamn</td>
    <td style="text-align: left" class="style8">
            <asp:TextBox ID="UsrNme" runat="server" Width="258px" Height="20px"></asp:TextBox>
        </td>
   <td>
       <asp:RequiredFieldValidator ID="Userreqlbl" runat="server" 
           ControlToValidate="UsrNme" ErrorMessage="This field is required" ForeColor="Red"></asp:RequiredFieldValidator><br />
       <br />
       </td>


   </tr>


    <tr>
        <td class="style5">
            &nbsp; Förnamn
        </td>
        <td style="text-align: left" class="style8">
            <asp:TextBox ID="fnbox" runat="server" Height="20px" Width="258px" 
                ></asp:TextBox>
        </td>
        <td style="text-align: left">
            &nbsp;
        </td>
    </tr>

    <tr>
        <td class="style5">
            &nbsp; Efternamn
        </td>
        <td style="text-align: left" class="style8">
            <asp:TextBox ID="lnamebox" runat="server" Height="20px" Width="258px"></asp:TextBox>
        </td>
        <td style="text-align: left">
            &nbsp;
        </td>
    </tr>

    <tr>
        <td class="style5">
            &nbsp; Lösenord
        </td>
        <td style="text-align: left" class="style8">
            <asp:TextBox ID="passtxtbx1" runat="server" TextMode="Password" Width="258px" Height="20px"></asp:TextBox>
        </td>
        <td style="text-align: left">
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="passtxtbx1"
                ErrorMessage="This part is required" ForeColor="Red"></asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td class="style5">
            &nbsp; Återskrivnings Lösenord
        </td>
        <td style="text-align: left" class="style8">
            <asp:TextBox ID="passtxtbx2" runat="server" TextMode="Password" Width="258px" Height="20px"></asp:TextBox>
        </td>
        <td style="text-align: left">
            <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="passtxtbx1"
                ControlToValidate="passtxtbx2" ErrorMessage="The password is not match" ForeColor="Red"></asp:CompareValidator>
        </td>
    </tr>
    <tr>
        <td class="style5">
            &nbsp; E-post
        </td>
        <td style="text-align: left" class="style8">
            <asp:TextBox ID="emailbox" runat="server" Height="20px" Width="258px"></asp:TextBox>
        </td>
        <td style="text-align: left">
            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="emailbox"
                ErrorMessage="Invalid Format" ForeColor="Red" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
            &nbsp;
        </td>
    </tr>
    <tr>
        <td class="style5">
            &nbsp; Land
        </td>
        <td style="text-align: left" class="style8">
            <asp:DropDownList ID="countrdrdolst" runat="server" AutoPostBack="True" 
                onselectedindexchanged="countrdrdolst_SelectedIndexChanged">
            </asp:DropDownList>
        </td>
        <td style="text-align: left">
            &nbsp;</td>
    </tr>
    <tr>
        <td class="style5">
            &nbsp; Län
        </td>
        <td style="text-align: left" class="style8">
            <asp:DropDownList ID="statedrdolst" runat="server" AutoPostBack="True" 
                onselectedindexchanged="statedrdolst_SelectedIndexChanged">
            </asp:DropDownList>
        </td>
        <td style="text-align: left">
            &nbsp;</td>
    </tr>
    <tr>
        <td class="style5">
            &nbsp; Stad
        </td>
        <td style="text-align: left" class="style11">
            <asp:DropDownList ID="citiesdrdolst" runat="server" AutoPostBack="True" 
                onselectedindexchanged="citiesdrdolst_SelectedIndexChanged">
            </asp:DropDownList>
        </td>
        <td style="text-align: left" class="style12">
        </td>
    </tr>


    <tr>
        <td class="style5">
            &nbsp; Postnummer
        </td>
        <td style="text-align: left" class="style8">
            <asp:TextBox ID="postbox" runat="server" Width="258px" CausesValidation="True" 
                Height="20px"></asp:TextBox>
        </td>
        <td style="text-align: left">
            &nbsp;
        </td>
    </tr>
    <tr>
        <td class="style5">
            &nbsp; Personlig bild
        </td>
        <td style="text-align: left" class="style8">
            <asp:FileUpload ID="FileUpload1" runat="server" />
        </td>
        <td style="text-align: left">
            &nbsp;
        </td>
    </tr>
   <tr>
   <td>


   </tr>
    <tr>
        <td class="style5">
            &nbsp;
            </td>
        <td class="style8">

            <asp:Button ID="btnSave" runat="server" Text="Create" onclick="btnSave_Click" />



        </td>
        <td>
            &nbsp;</td>
    </tr>
</table>
<br />
<br />
<br />
</ContentTemplate>
</asp:UpdatePanel>

0 个答案:

没有答案