How Javascript work with our method? ( using C# , .net 2.0)

Last post 11-08-2009 3:22 AM by raju dasa. 3 replies.

Sort Posts:

  • How Javascript work with our method? ( using C# , .net 2.0)

    11-07-2009, 3:00 PM
    • Member
      17 point Member
    • isjf
    • Member since 03-06-2008, 7:32 AM
    • Posts 429

    I am not similiar with javascript ... just star to learning it


    in my web page have a Dropdownlist (names ddlSHOP) and 100 textboxes

    each time ddlSHOP.selectedIndex changed , I will change the text of each texBox

    (depend on which shop user selected .. then fill the shop's information to each textbox)


    for to avoid user miss the information they just modify ( user will change any of textbox.Text )

    I hope I can ask user if they want to save data before I change TextBox.Text each time ddlShop.SelectedIndexChanged..


    1 user selecte the shop from ddlSHOP

    2 I will retrive data from database then fill data to each TextBox of the shop was seleced by user

    3 user change ddlShop's selectedIndex

    4 I want to pop-up alert window to ask user if theny want to save the data before change selected shop ?

    5 if user click "yes" then save data for them, after saved , retrieve another shop's information then fill to each textboxes for user again


    in step 4 and step 5

    step 4 : how to pop up window when user change ddlSHOP's selctedindex by javascript?

    step5 : I have wirte a method named SaveShop for save data... how to invoke this method by javascript?

    private book SaveShop(string shopID)

    {

    // save data

    }


    I will be appreciated for any suggestion..


    thanks alot





  • Re: How Javascript work with our method? ( using C# , .net 2.0)

    11-07-2009, 8:28 PM
    Answer
    • Member
      301 point Member
    • jclark434175
    • Member since 01-13-2008, 10:15 PM
    • Cleveland
    • Posts 46

    This code will show you how to capture on the onchange event of the drop down list on the client side so you can open pop ups, etc. This should also give you a pretty good head start on what you are trying to accomplish. 

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <script type="text/javascript">
            function myJSFunction() {
                //Do Something
                alert('What value do you need?');
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div class="myLabelStyle">
            <asp:Label ID="myLabel" runat="server" Text="My Label Text"></asp:Label>
            <asp:DropDownList ID="myDDL" runat="server" onchange="myJSFunction(this);" >
                <asp:ListItem Text="Item1"></asp:ListItem>
                <asp:ListItem Text="Item2"></asp:ListItem>
                <asp:ListItem Text="Item3"></asp:ListItem>
                <asp:ListItem Text="Item4"></asp:ListItem>
            </asp:DropDownList>
        </div>
        </form>
    </body>
    </html>


    Hope this helpsSmile

    My Blog
    jclark434175@gmail.com

    Please mark this question as answered if it helped you. Thanks!

    "People don't care how much you know until they know how much you care."
  • Re: How Javascript work with our method? ( using C# , .net 2.0)

    11-07-2009, 11:33 PM
    • Star
      12,629 point Star
    • malcolms
    • Member since 06-12-2008, 4:38 AM
    • Melbourne, Australia
    • Posts 2,078

    isjf:

    step 4 : how to pop up window when user change ddlSHOP's selctedindex by javascript?

    step5 : I have wirte a method named SaveShop for save data... how to invoke this method by javascript?

    private book SaveShop(string shopID)

    {

    // save data

    }

    To run JavaScript when they change the dop down list, you need to bind to the select event.  Like this:

    <html>
    <head>
    <script src="http://code.jquery.com/jquery-latest.js"></script>

    <script>
    $(document).ready(function(){

    $("select").change(function () {
    var str = "";
    $("select option:selected").each(function () {
    str += $(this).text() + " ";
    });
    $("div").text(str);
    })
    .change();

    });
    </script>
    <style>
    div { color:red; }
    </style>
    </head>
    <body>
    <select name="sweets" multiple="multiple">
    <option>Chocolate</option>
    <option selected="selected">Candy</option>
    <option>Taffy</option>
    <option selected="selected">Caramel</option>
    <option>Fudge</option>
    <option>Cookie</option>
    </select>
    <div></div>
    </body>
    </html>

    To get the JavaScriopt code to call a server method you'll need to use Ajax. Take a look at one of my articles on how to do that.

    http://www.dotnetcurry.com/ShowArticle.aspx?ID=404
    Sincerely,
    Malcolm Sheridan

    Microsoft Certified Solution Developer
    Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as
    Answer" if a marked post does not actually answer your question.
  • Re: How Javascript work with our method? ( using C# , .net 2.0)

    11-08-2009, 3:22 AM
    • Participant
      946 point Participant
    • raju dasa
    • Member since 11-05-2008, 11:20 AM
    • Posts 184

    HI

      try applying 'onfocus' event to dropdownlist and handle it in javascript instead of onchange event. once user selects yes to save, write the status into a hidden field and update the database at serverside once postback is done, based on status in hidden field.

    --------------------------------------

    Happy coding. 

Page 1 of 1 (4 items)