1
votes

Input value is updated properly when in page load:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        txtSupplierType.Value = "Local";
    }
}

but when we try to update it from other control events like:

ASPX Page

 <asp:DropDownList runat="server" ID="ddlProduct" name="form-control" class="form-control select-chosen" OnSelectedIndexChanged="ddlProduct_SelectedIndexChanged" AutoPostBack="true"> </asp:DropDownList>

SelectedIndexChanged Event

 protected void ddlProduct_SelectedIndexChanged(object sender, EventArgs e)
    {
        txtSupplierType.Value = "Global";
    }

it won't update and many other html controls with runat="server" do not work as in page load:

<input type="text" id="txtSupplierType" runat="server" name="example-text-input" class="form-control" />
1
Post more code, at least ddlProduct definition. For example did you set AutoPostBack="true" for it? - Luca
yes. <asp:DropDownList runat="server" ID="ddlProduct" name="form-control" class="form-control select-chosen" OnSelectedIndexChanged="ddlProduct_SelectedIndexChanged" AutoPostBack="true" onchange="changedropdown()" > </asp:DropDownList> - Haroon Hussain
you may use update panel on input element for change control behavior from server side. - Sanjay Radadiya
still not updating after adding in to "asp:UpdatePanel" - Haroon Hussain
thanks everyone. It works . adding both event contol and updating controll in same updatepanel works for me - Haroon Hussain

1 Answers

1
votes

Here is complete code that will work according to your requirement.

<asp:UpdatePanel ID="PnlUsrDetails" runat="server">
                <ContentTemplate>
                    <asp:DropDownList runat="server" ID="ddlProduct"                                                                             name="form-control" 
                        class="form-control select-chosen" 
                        OnSelectedIndexChanged="ddlProduct_SelectedIndexChanged" 
                        AutoPostBack="true"> </asp:DropDownList>

                    <input type="text" id="txtSupplierType" runat="server"
                         name="example-text-input" class="form-control" />
                </ContentTemplate>
            </asp:UpdatePanel>

this code works because this is how update panel works. it will start async postback whenever your control in update panel changes the state. and by default update mode property of update panel is set to "Automatically". so only the code in content template of update panel will be sent to server and come back with updated information.

and you better provide whole code so other users can understand the code and help you much better way.