Values ​​lost in postback when javascript changes

I change ImageUrl ImageButtons using Javascript when the user translates with the mouse. On sending, I want to check the ImageUrl property. However, the changed property is not reflected in the code behind. In fact, I am also updating the span tag through javascript, and its changed value is also not reflected in the return mail. These are all static html elements. I do not create any of them dynamically and do not do any manipulations with them in the code.

HTML

            <div style="margin: 20px 0 0 0; float: left;">
        <div class="divStars1" style="width: 130px; float: left;">
            <input type="image" name="ctl00$MainContent$ax1" id="MainContent_ax1" class="stars" onmouseover="<code to flip image>" src="style/EmptyStar.png" style="height:20px;width:20px;" />
            <input type="image" name="ctl00$MainContent$ax2" id="MainContent_ax2" class="stars" onmouseover="<code to flip image>" src="style/EmptyStar.png" style="height:20px;width:20px;" />
            <input type="image" name="ctl00$MainContent$ax3" id="MainContent_ax3" class="stars" onmouseover="<code to flip image>" src="style/EmptyStar.png" style="height:20px;width:20px;" />
            <input type="image" name="ctl00$MainContent$ax4" id="MainContent_ax4" class="stars" onmouseover="<code to flip image>" src="style/EmptyStar.png" style="height:20px;width:20px;" />
            <input type="image" name="ctl00$MainContent$ax5" id="MainContent_ax5" class="stars" onmouseover="<code to flip image>" src="style/EmptyStar.png" style="height:20px;width:20px;" />

        </div>
        <div style="margin-top: 3px; width: 600px; float: left;">
            <span>axs</span>
        </div>
    </div>
    <div style="margin: 20px 0 0 0; float: left;">
        <div class="divStars2" style="width: 130px; float: left;">
            <input type="image" name="ctl00$MainContent$bx1" id="MainContent_bx1" class="stars" onmouseover="<code to flip image>" src="style/EmptyStar.png" style="height:20px;width:20px;" />
            <input type="image" name="ctl00$MainContent$bx2" id="MainContent_bx2" class="stars" onmouseover="<code to flip image>" src="style/EmptyStar.png" style="height:20px;width:20px;" />
            <input type="image" name="ctl00$MainContent$bx3" id="MainContent_bx3" class="stars" onmouseover="<code to flip image>" src="style/EmptyStar.png" style="height:20px;width:20px;" />
            <input type="image" name="ctl00$MainContent$bx4" id="MainContent_bx4" class="stars" onmouseover="<code to flip image>" src="style/EmptyStar.png" style="height:20px;width:20px;" />
            <input type="image" name="ctl00$MainContent$bx5" id="MainContent_bx5" class="stars" onmouseover="<code to flip image>" src="style/EmptyStar.png" style="height:20px;width:20px;" />
        </div>
        <div style="margin-top: 3px; width: 600px; float: left;">
            <span>bx blah blah</span>
        </div>
    </div>

JavaScript:

        $(document).on("mouseover", "input.stars", function () {
        var score = 0;
        $("input.stars").each(function (index, element) {
            // element == this
            if ($(element).attr("src") == "style/FilledStar.png") {
                score = score + 1;
            };
        });
        score = score / 5;
        var n = score.toFixed(2);
        $("#MainContent_lblScore").text(n);
    });

btnSubmit_Click code:

        For Each ctrl As Control In Me.divSkill1.Controls
        If (TypeOf ctrl Is ImageButton) Then
            Dim imgCtl As ImageButton = TryCast(ctrl, ImageButton)
            Dim x As String = imgCtl.ImageUrl 'HERE THE PROBLEM... x always equals original static value!
        End If

    Next
+4
source share
2 answers

.

<asp:HiddenField />, JavaScript . HiddenFields/<input type="hidden" /> PostBack. HiddenField ImageButton ImageUrl.

+4

. , , javascript , .

,

Edit:

var n, - :

//aspx;

<asp:HiddenField ID="HidScore" runat="server" />

///javascript

$(document).on("mouseover", "input.stars", function () {
    var hid=$("#<%= HidScore.ClientID %>");


        var score = 0;
        $("input.stars").each(function (index, element) {
            // element == this
            if ($(element).attr("src") == "style/FilledStar.png") {
                score = score + 1;
            };
        });
        score = score / 5;
        var n = score.toFixed(2);
        $("#MainContent_lblScore").text(n);

    hid.val(n);
    });

vb.net : HidScore.value

+7

All Articles