You must Sign In to post a response.
  • Category: ASP.NET

    How to Change TextBox Or Label Value by DropDown SelectedValue Without PageLoad in asp.net

    Hi Developers,

    I need to Perform following task.
    There is a page called sample.i have dropdown list with some City Name.

    If i select Chennai in dropdown na Rate Should be 1000
    if i Select Mumbai in dropdown na Rate Should be 2000
    This is Changes when user Selecting dropdown Value But The Page is did not Loaded.

    i need to perform this event Without Pageload.

    if anyone of you know please help me to i am done this task.

    Thanking You
    Paul.S
  • #766946
    You have to call ajax request client and server page functionality you can redirect the page to another page with ajax request and response will be back to the original event without calling the pageload event of that particular page.
    SRI RAMA PHANI BHUSHAN KAMBHAMPATI

  • #766947
    Below url is an apt solution for your question please refer it.
    http://www.codeproject.com/Articles/16751/Implementing-AJAX-in-your-Applications-How-Simple

    SRI RAMA PHANI BHUSHAN KAMBHAMPATI

  • #766953
    If you want to handle this in the Javascript dropdown, you can use the property "dependentvalue"
    Following is the way to add the dependent values in the dropdown control. You can add the multiple value using the ";" splitter.

    var oOption = document.createElement("OPTION");
    oOption.value = value;
    oOption.setAttribute("dependentvalue", "Your value");
    document.getElementById('DDControl').options.add(oOption);


    you can get the dependent value as follows

    obj[obj.selectedIndex].getAttribute("dependentvalue").split(';');

    By Nathan
    Direction is important than speed

  • #766961
    according to Page life cycle, when you execute any request (postback) page gets destroyed and re-created again, and the code you write on server side (code behind) is executed after page_load only, so here I think you have write code on 'combo_selectedIndexChanged' event
    To avoid postback either you need to use UpdatePanel or use client side scripting to fill gridview
    UpdatePanel controls work by specifying regions of a page that can be updated without refreshing the whole page. This process is coordinated by the ScriptManager server control and the client PageRequestManager class
    use below link
    http://ajax.net-tutorials.com/controls/updatepanel-control/

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #766962
    Hi Paul,

    As per my understanding you want to stop the post back of the page after selecting item in dropdown, my suggestion use AJAX UpdatePanel and use Triggers for stop to postback, use AsyncPostBackTrigger template and pass the EventName which event you want to stop postback.

    Ex:

    <asp:UpdatePanel ID="upCancel" runat="server" UpdateMode="Always">
    <ContentTemplate>
    <asp:ImageButton ID="btnCancelYes" OnClick="btnCancelYes_Click" runat="server"
    ImageUrl="~/Images/btnyes.jpg" />
    <a href="javascript:void(0)" onclick="closepopup()">
    <img src="~/Images/btnNo.jpg" style="border: 0px" align="right" /></a>
    </ContentTemplate>
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="btnCancelYes" EventName="Click" />
    </Triggers>
    </asp:UpdatePanel>



    Use the above sample and implement the same in your case.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #766965
    Hi,
    You do this using javascript.
    First make AutoPostBack property =false for dropdown and call javascript function onchange as follows.

    <script type="text/javascript">
    function xyz()
    {
    document.getElementById("TextBox1").innerText = document.getElementById("ddlDemo").value;
    }
    </script>
    <asp:DropDownList runat="server" ID="ddlDemo" AutoPostBack="false" onchange="javascript:return xyz();">
    <asp:ListItem Text="" />
    <asp:ListItem Text="text1" />
    <asp:ListItem Text="text2" />
    </asp:DropDownList>

  • #766966
    Thanks , thanks a lot for all of your Kindful replies dear friends.
    You are always helping me.

  • #766978
    Hi
    Paul

    you can use client side script(Jscript) for this task
    I work and post this code try and let me know.




    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    <script>

    function Jscriptvalues() {
    var cval = document.getElementById("DDLCITY").value;
    if (cval == 1) {
    document.getElementById("TxtAmount").value = 1000;
    }
    else {
    if (cval == 2) {
    document.getElementById("TxtAmount").value = 2000;
    }
    }
    }

    </script>
    </head>
    <body>
    <form id="form1" runat="server">
    <asp:DropDownList ID="DDLCITY" runat="server" onchange="return Jscriptvalues();">
    <asp:ListItem Text="-Select-" Value="0">-Select-</asp:ListItem>
    <asp:ListItem Text="Chennai" Value="1">Chennai</asp:ListItem>
    <asp:ListItem Text="Mumbai" Value="2">Mumbai</asp:ListItem>
    </asp:DropDownList>
    <asp:TextBox ID="TxtAmount" runat="server"></asp:TextBox>
    </form>
    </body>
    </html>


    Name : Dotnet Developer-2015
    Email Id : kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.


  • Sign In to post your comments