为什么在回发期间丢失了DropDownList值?

时间:2014-01-10 09:59:27

标签: c# javascript asp.net drop-down-menu postback

当我触发回发时,我有DropDownList的值。这是我的aspx,JavaScript和C#代码。

使用Javascript:

<script type="text/javascript">
    function stfocus(event) {
        if (event.keyCode == 13) {
            document.getElementById('tbfrompalletno').focus();
        }
    }

    function tblocenter(event) {
        if (event.keyCode == 13) {
            __doPostBack('__Page', 'save');
        }
    }
</script>

ASPX:

 <table>
    <tr>
        <td colspan="2" style="text-anchor: middle; text-align: center; border: thin solid #000000; background-color: #CCCCCC;">
            <asp:Label ID="lblheader" runat="server" Text="Partial Pallet Transfer"></asp:Label>
        </td>
    </tr>

    <tr>
        <td colspan="2" style="text-align: left">
            <asp:Label ID="Label_ErrorMsg" runat="server" Text="" BackColor="Red" ForeColor="White" />
            <asp:Label ID="Label_Info" runat="server" Text="" BackColor="Green" ForeColor="White" />
        </td>
    </tr>

    <tr>
        <td>
            <asp:Label ID="lblwhscode" runat="server" Text="WHS Code:"></asp:Label>
        </td>
        <td>
            <asp:DropDownList ID="cbwhscode" runat="server" 
                DataSourceID="sql_whs_code" DataTextField="whs_name" DataValueField="whs_code">
            </asp:DropDownList>
        </td>
    </tr>

    <tr>
        <td>
            <asp:Label ID="lblfromloc" runat="server" Text="From Location:"></asp:Label>
        </td>

        <td>
            <asp:TextBox ID="tbfromloc" runat="server"></asp:TextBox>
        </td>
    </tr>

    <tr>
        <td>
            <asp:Label ID="lblfrompalletno" runat="server" Text="From Pallet:"></asp:Label>
        </td>

        <td>
            <asp:TextBox ID="tbfrompalletno" runat="server"></asp:TextBox>
        </td>
    </tr>

    <tr>
        <td colspan="2" style="text-align: center;">
            <asp:Button ID="btnsubmit" runat="server" Text="Submit" OnClick="btnsubmit_Click" UseSubmitBehavior="false" />
            <asp:Button ID="btnback" runat="server" Text="Back" OnClick="btnback_Click" UseSubmitBehavior="false" />
            <asp:Button ID="btnhome" runat="server" Text="Home" OnClick="btnhome_Click" UseSubmitBehavior="false" />
        </td>
    </tr>
</table>
<asp:SqlDataSource ID="sql_whs_code" runat="server" ConnectionString="<%$ ConnectionStrings:infologConnection %>"
    SelectCommand="sp_select_auth_whs_code" SelectCommandType="StoredProcedure" OnSelecting="sql_whs_code_Selecting">
    <SelectParameters>
        <asp:Parameter Name="group_id" Type="String" />
    </SelectParameters>
</asp:SqlDataSource>

C#:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.tbfromloc.Attributes.Add("onkeydown", "javascript:stfocus(event);");
            this.tbfrompalletno.Attributes.Add("onkeydown", "javascript:tblocenter(event);");

            ViewState["language"] = (string)Session["language"];
            ViewState["group_id"] = (string)Session["group_id"];

            this.loadsetting();
            this.cbwhscode.DataBind();

            if (this.cbwhscode.Items.Count > 0)
            {
                ListItem Check = this.cbwhscode.Items.FindByValue(Session["default_whs_code"].ToString());

                if ((Check != null) && this.cbwhscode.Items.Contains(Check))
                {
                    this.cbwhscode.SelectedValue = Session["default_whs_code"].ToString();
                }
            }
            this.tbfromloc.Focus();
        }

        string parameter = Request["__EVENTARGUMENT"];
        if (parameter = "save" ) this.btnsubmit_Click(sender, e);
    }

    protected void btnsubmit_Click(object sender, EventArgs e)
    {
        this.Label_ErrorMsg.Text = "";
        this.Label_Info.Text = "";

        string i_whs_code = this.cbwhscode.SelectedValue;
        string i_pack_id = this.tbfrompalletno.Text;
        string i_loc_code = this.tbfromloc.Text;

        Tuple<bool, int, string> result = RF03BLL_Transfer.rf_partial_transfer_check_loc_pallet(i_whs_code, i_pack_id, i_loc_code);
        bool o_succeed = result.Item1;
        int o_msg_num = result.Item2;
        string o_add_info = result.Item3;

        if (o_succeed)
        {
            string strPost = "whscode=" + HttpUtility.UrlEncode(i_whs_code) +
                            "&palletno=" + HttpUtility.UrlEncode(i_pack_id) +
                            "&loccode=" + HttpUtility.UrlEncode(i_loc_code);
            string path = "~/RF03F_Transfer/RF030202F_TransferPartialAddPacking.aspx?";
            path += strPost;
            Response.Redirect(path);
        }
        else
        {
            this.Label_ErrorMsg.Text = Module.getMsg(o_msg_num, ViewState["language"].ToString());
        }
    }

    protected void sql_whs_code_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {
        e.Command.Parameters["@group_id"].Value = ViewState["group_id"].ToString();
    }

我的问题是:为什么错过了DropDownList的价值?

0 个答案:

没有答案