|
-
Jan 31st, 2012, 08:50 AM
#1
Thread Starter
Hyperactive Member
[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?
-
Jan 31st, 2012, 09:07 AM
#2
Thread Starter
Hyperactive Member
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.
-
Feb 1st, 2012, 03:26 PM
#3
Re: Set element value using jQuery, but did not change when post to code behind
-
Feb 1st, 2012, 03:31 PM
#4
Thread Starter
Hyperactive Member
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
-
Feb 1st, 2012, 03:33 PM
#5
Re: Set element value using jQuery, but did not change when post to code behind
-
Feb 1st, 2012, 03:35 PM
#6
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|