Results 1 to 6 of 6

Thread: [RESOLVED] Set element value using jQuery, but did not change when post to code behind

  1. #1

    Thread Starter
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    Resolved [RESOLVED] Set element value using jQuery, but did not change when post to code behind

    I got a asp:label (hidden by css) to which I store something.

    I could not use a hiddenfield since you cannot set a css class on it.
    I need a css class so I can select it in jQuery.
    I cannot select by Id since asp.net webforms change your id.
    I cannot use xxxxx.ClientId, since my jQuery script isn't on that form (oh oh, i miss my mvc)

    Anyhow, I pop up a dialog, let the user type sth in.
    When the dialog closes, I set that label to whatever the use typed in the dialog.
    That work (I'm testing for now using some alerts) but when I add a button, and in it's click event check the value of taht label, it is still what it originally have been though. (hmmmm....what I missed?)

    Here is the content of my usercontrol (at run time add as many as needed of them to my view):
    Code:
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DisputeEntry.ascx.cs" Inherits="TimeSheetDispute.DisputeEntry" %>
    <p class="field switch">
        <asp:label runat="server" class="disputeReason" ID="disputeReason"></asp:label>
        <label class="cb-enable selected"><span>Y</span></label>
        <label class="cb-disable"><span>N</span></label>
        <input type="checkbox" id="checkbox" class="checkbox" />
        <asp:TextBox CssClass="workDateId" ID="workDateId" runat="server"></asp:TextBox>
    </p>
    And in my page, the code that deal with it:
    Code:
    // Brings up a jQuery UI Dialog containing a textarea to which the user can enter a dispute
    // Upon close, place that reason in the hidden input we keep for each date.
    function GetDisputeReason(parent) {
        var disputeReasonElement = $('.disputeReason', parent);
        var existingDispute = disputeReasonElement.val();
        var win = $('<div><p>Enter your reason for dispute:</p></div>');
        var userInput = $('<textarea style="width:100%">' + existingDispute + '</textarea>');
        userInput.appendTo(win);
        $(win).dialog({
            'modal': true,
            'buttons': {
                'Ok': function () {
                    $(this).dialog('close');
                    var reason = $(userInput).val();
                    alert(disputeReasonElement.val());
                    disputeReasonElement.val(reason);
                    alert(disputeReasonElement.val());
                },
                'Cancel': function () {
                    $(this).dialog('close');
                    return '';
                }
            }
        });
    }
    Those alert's confirm the value of my label have been set.
    (dang I just remembered sth about webforms..that value probably sit in the viewstate and my code read that, not the value of my label)

    Any ideas?


  2. #2

    Thread Starter
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    Re: Set element value using jQuery, but did not change when post to code behind

    *sight*
    Forgot (again) asp:label = <span>
    So I swapped it out with asp:Textbox and changed the jquery to set .text() instead of .val()
    Getting a jQuery error though "htmlfile: Unexpected call to method or property access." uurgh.


  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Set element value using jQuery, but did not change when post to code behind


  4. #4

    Thread Starter
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    Re: Set element value using jQuery, but did not change when post to code behind

    hmmm...there's 2 hidden fields per control.
    but then, you got a point. I know which is first and second. :-D


  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Set element value using jQuery, but did not change when post to code behind

    Yip yip yip.

    Gary

  6. #6

    Thread Starter
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    Re: Set element value using jQuery, but did not change when post to code behind

    Without trying that would work. Thanks!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width