Click here to Skip to main content
15,922,574 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using update panel on two dropdown. I want when selecting value from country dropdown corresponding state will appear in state dropdown, it is done but as I select value from country dropdown whole page is refreshing, which i dont want. What can i do for this?


here is my aspx page code:



XML
<asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
    <div>
    <table>
    <tr>
    <td>First Name
    </td>
    <td>
        <asp:TextBox ID="txtfname" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
            ErrorMessage="Enter First Name" ControlToValidate="txtfname"></asp:RequiredFieldValidator>
    </td>
    </tr>
    <tr>
    <td class="style1">Last Name
    </td>
    <td class="style1">
        <asp:TextBox ID="txtlname" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
            ErrorMessage="Enter Last  Name" ControlToValidate="txtlname"></asp:RequiredFieldValidator>
    </td>
    </tr>


    <tr>

    <td>User Name
    </td>
    <td>


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


                <asp:TextBox ID="txtuname" runat="server" AutoPostBack="True"
            ontextchanged="TextBox1_TextChanged"></asp:TextBox>
        <asp:Label ID="lbluname" runat="server" Visible="false" ></asp:Label>

        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
            ErrorMessage="Enter User Name" ControlToValidate="txtuname"></asp:RequiredFieldValidator>
            </ContentTemplate>
            <Triggers>
            <asp:PostBackTrigger ControlID="txtuname" />
            <%--<asp:AsyncPostBackTrigger ControlID="txtuname" EventName="TextChanged" />--%>
            </Triggers>
        </asp:UpdatePanel>



        <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
        <ProgressTemplate>
        <img src="images/ajax.gif" width="50px" height="50px" />
        </ProgressTemplate>
        </asp:UpdateProgress>

    </td>
    

    </tr>



    <tr>
    <td>Gender
    </td>
    <td>

        <asp:RadioButtonList ID="rbgender" runat="server"
            RepeatDirection="Horizontal">
            <asp:ListItem>Male</asp:ListItem>
            <asp:ListItem>Female</asp:ListItem>
        </asp:RadioButtonList>

        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
            ControlToValidate="rbgender" ErrorMessage="Select Gender"></asp:RequiredFieldValidator>

    </td>
    </tr>
    <tr>
    <td>Email
    </td>
    <td>

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



        <asp:TextBox ID="txtemail" runat="server" ontextchanged="txtemail_TextChanged"
            AutoPostBack="True"></asp:TextBox>
            <asp:Label ID="lblemail" runat="server" Visible="false" ></asp:Label>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
            ControlToValidate="txtemail" ErrorMessage="Enter Email"></asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
            ErrorMessage="Enter correct format" ControlToValidate="txtemail"
            ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
        <asp:CompareValidator ID="CompareValidator1" runat="server"
            ErrorMessage="Enter Same Email address" ControlToCompare="txtemail"
            ControlToValidate="txtConfirmemail"></asp:CompareValidator>
            </ContentTemplate>
            <Triggers>
            <asp:PostBackTrigger ControlID="txtemail" />
            </Triggers>
        </asp:UpdatePanel>
        <asp:UpdateProgress ID="UpdateProgress2" runat="server" AssociatedUpdatePanelID="UpdatePanel2">
        <ProgressTemplate>
        <img src="images/ajax.gif" width="50px" height="50px" />
        </ProgressTemplate>
        </asp:UpdateProgress>
    </td>
    </tr>
    <tr>
    <td>Confirm Email
    </td>
    <td>
        <asp:TextBox ID="txtConfirmemail" runat="server"></asp:TextBox>
    </td>
    </tr>

    <tr>
    <td>Password
    </td>
    <td>
        <asp:TextBox ID="txtpassword" runat="server" TextMode="Password"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
            ErrorMessage="Enter Password" ControlToValidate="txtpassword"></asp:RequiredFieldValidator>
        <asp:CompareValidator ID="CompareValidator2" runat="server"
            ErrorMessage="Enter same password" ControlToCompare="txtpassword"
            ControlToValidate="txtconfirmpassword"></asp:CompareValidator>
    </td>
    </tr>
    <tr>
    <td>Confirm Password
    </td>
    <td>
        <asp:TextBox ID="txtconfirmpassword" runat="server" TextMode="Password"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td>DOB
    </td>
    <td>
        <asp:TextBox ID="txtdob" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"
            ErrorMessage="Enter DOB" ControlToValidate="txtdob"></asp:RequiredFieldValidator>
    </td>
    </tr>
    <tr>
    <td>Address
    </td>
    <td>
        <asp:TextBox ID="txtaddress" runat="server" TextMode="MultiLine"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server"
            ErrorMessage="Enter Address" ControlToValidate="txtaddress"></asp:RequiredFieldValidator>
    </td>
    </tr>


        <asp:UpdatePanel ID="up1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
    <tr>
    <td>
        Country
    </td>
    <td>
        <asp:DropDownList ID="ddlcountry" runat="server" AutoPostBack="True"
            onselectedindexchanged="ddlcountry_SelectedIndexChanged">
        </asp:DropDownList>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server"
            ErrorMessage="Choose Country" ControlToValidate="ddlcountry"></asp:RequiredFieldValidator>
    </td>
    </tr>




    <tr>
    <td>State
    </td>
    <td>
        <asp:DropDownList ID="ddlstate" runat="server" >

        </asp:DropDownList>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server"
            ErrorMessage="Choose State" ControlToValidate="ddlstate"></asp:RequiredFieldValidator>
    </td>
    </tr>

   </ContentTemplate>
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="ddlcountry"  />
   <%--<asp:PostBackTrigger ControlID="ddlcountry" />--%>
    </Triggers>
    </asp:UpdatePanel>

    


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




    <tr>
    <td>PinCode
    </td>
    <td>
        <asp:TextBox ID="txtpincode" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server"
            ErrorMessage="Enter Pin Code" ControlToValidate="txtpincode"></asp:RequiredFieldValidator>
    </td>
    </tr>
    <tr>
    <td>
    </td>
    <td>
        <asp:Button ID="btnsubmit" runat="server" Text="Submit"
            onclick="btnsubmit_Click" />
    </td>
    </tr>
    </table>
    </div>
Posted
Updated 11-Jul-13 22:39pm
v2
Comments
Deenuji 12-Jul-13 4:44am    
you can do this something without ajax.....if you using selected index changing event means you can achieve same functionalities....
Gaurav Agarwal from Jaipur 12-Jul-13 5:21am    
how sir?
Nandakishore G N 12-Jul-13 5:31am    
you cant add the updatepanel for particular <tr> if you are using <table> structure.Use Divs or place updatepanel to whole table then it works.
Gaurav Agarwal from Jaipur 12-Jul-13 5:36am    
still not working sir..
Gaurav Agarwal from Jaipur 12-Jul-13 5:51am    
any other solution sir?

use

if (!IsPostBack)in pageload
 
Share this answer
 
Comments
Gaurav Agarwal from Jaipur 12-Jul-13 5:33am    
Sir I am asking about update panel! I dont want the whole page refreshing? what can i do?
Hi,

Might be ur implementing update pannel wrongly.
I used ur design code n try with following modification.It work pefectly without refreshing
whole page.



XML
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
            <ContentTemplate>
                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
                    onselectedindexchanged="DropDownList1_SelectedIndexChanged">
                    <asp:ListItem Value="0">India</asp:ListItem>
                    <asp:ListItem Value="1">US</asp:ListItem>
                    <asp:ListItem Value="3">China</asp:ListItem>
                </asp:DropDownList>
                <br />
<br />
                <asp:DropDownList ID="DropDownList2" runat="server">
                </asp:DropDownList>
            </ContentTemplate>
        </asp:UpdatePanel>


I hope it will work.
 
Share this answer
 
Comments
Gaurav Agarwal from Jaipur 12-Jul-13 6:17am    
sir i am using the same code..but still not working..
Gaurav Agarwal from Jaipur 12-Jul-13 6:18am    
if i am using only these dropdown to seperate page then it is working..but i my registration page it is not working..
ranjeet.waje 12-Jul-13 6:51am    
Hi gaurav,

I used ur all design and just replace ur droplist panel with above one.
not on sepearte page
Gaurav Agarwal from Jaipur 12-Jul-13 7:40am    
Thank u Sir! I am also using this but not working..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900