English 中文(简体)
1. AsyncPostBack后,Javascript的一笔款项,造成损失。 三、更新小组
原标题:Dropdownlist(ddlState) value loss when acess in Javascript after AsyncPostBackTrigger in update panel

我有德勒克邦退学和德勒邦退学名单。 ddlState正在更新小组。 在选择国家时,我利用选定的国家资格指数变化活动,使国家人口众多。 我将起始值“-1”提高到了约束后退学的两倍,如果退学内容为[当选]价值“-1”,则在 Java文中检查,然后提醒人们注意并退回错误。

但是,对于干.的国家来说,补偿是适当的,而对于干.的国家来说,其价值在加亚克斯更新小组火灾和验证失败后成为“空白”。

如何解决这些问题? 我无意知道,为何在阿斯辛茨·波斯特·巴克谢格之后,损失了dl国家的价值。

  //javascript validation

        function validateForm()
                {
                    if (ddlCountry .value == "-1")
                    {
                        alert("Country  should not be blank.");
                        ddlCountry .focus();
                        return false;
                    }
                    if (ddlState .value == "-1")
                    {
                        alert("State should not be blank.");
                        ddlState .focus();
                        return false;
                    }

                    return true;
                }
        //Aspx code
<asp:DropDownList ID="ddlCountry " runat="server" CssClass="csstextbox" Width="207px"
                                AutoPostBack="true"  OnSelectedIndexChanged="ddlCountry _SelectedIndexChanged">
                            </asp:DropDownList>
                 <asp:UpdatePanel ID="updatePanelState" runat="server">
                                                    <ContentTemplate>                               
                        <asp:DropDownList ID="ddlState " runat="server" CssClass="csstextbox" Width="177px">
                                                        </asp:DropDownList>
                                                    </ContentTemplate>
                                                    <Triggers>
                                                        <asp:AsyncPostBackTrigger ControlID="ddlCountry" EventName="SelectedIndexChanged" />
                                                    </Triggers>
                                                </asp:UpdatePanel>
            //Code Behind

    protected void Page_Load(object sender, EventArgs e)
        {
               if(!IsPostBack)
            {
                    BindCountry();
                    }
            }
            protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
                {       
                    int countryID = Convert.ToInt32(ddlCountry.SelectedItem.Value);

                    ifcountryID == -1)
                    {
                        return;
                    }

                    strSQL = @"SELECT State_ID,State_Desc
                                FROM State_Master 
                                WHERE countryID =  " + countryID + @" ;

                    DataTable dataTableState = null;
                    dataTableState = objSqlDbComm.ExecuteDatasetQuery(strSQL).Tables[0];

                    var dictioneryState = new Dictionary<int, string>();
                    foreach(DataRow dr in dataTableStudy.Rows)
                    {
                        dictioneryState .Add(Convert.ToInt32(dr["State_ID"]), dr["State_Desc"].ToString());
                    }

                    ddlState.DataTextField = "Value";
                    ddlState.DataValueField = "Key";
                    ddlState.DataSource = dictioneryState;
                    ddlState.DataBind();
                    ddlState.Items.Insert(0, new ListItem("[Select]", "-1"));
                    ddlState.Items[0].Selected = true;          

                }
问题回答

下面两种降幅清单的正确性:

  <asp:DropDownList ID="ddlState " runat="server" CssClass="csstextbox" Width="177px" EnableViewState=true>                                                     </asp:DropDownList> 

它可能解决你的问题。

成就





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签