Javascript changes not saved

Discussion in 'ASP .Net Web Controls' started by ken s, Oct 10, 2006.

  1. ken s

    ken s Guest

    I'm using Javascript to change a value in an asp:textbox control on an
    asp.net page, then submitting the page and persisting the data using c# code.
    I can see the value in the textbox change when the Javascript runs, but when
    the page is submitted, the c# event code still sees the original value in the
    textbox, not the value that was updated by Javascript.


    Here’s the javascript code that changes the value:

    document.forms[0].txt1.value = calcCigScore();
    alert (document.forms[0].txt1.value);

    The alert shows me that the value has changed (I can also see it change on
    the page).


    And here’s the c# code from the SaveRecord event on the aspx page:

    mIntake.CigScore = int.Parse(txt1.Text);

    When tracing through the code, I see that txt1.Text still equals the value
    that was originally loaded into the page.

    Is there a reason why .Net doesn’t see the updated value? Anything I can do
    to change that?

    Thanks
    ken s, Oct 10, 2006
    #1
    1. Advertising

  2. Most likely you are running up against ViewState. Set up Page_Init() and
    look at the value there. Then, check again in Page_Load (ViewState runs
    between the two).

    It is also possible you are rebinding in Page_Load, which happens prior to
    the event handlers for controls (button submit, for example).

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA
    http://gregorybeamer.spaces.live.com

    *************************************************
    Think outside of the box!
    *************************************************
    "ken s" <> wrote in message
    news:...
    > I'm using Javascript to change a value in an asp:textbox control on an
    > asp.net page, then submitting the page and persisting the data using c#
    > code.
    > I can see the value in the textbox change when the Javascript runs, but
    > when
    > the page is submitted, the c# event code still sees the original value in
    > the
    > textbox, not the value that was updated by Javascript.
    >
    >
    > Here's the javascript code that changes the value:
    >
    > document.forms[0].txt1.value = calcCigScore();
    > alert (document.forms[0].txt1.value);
    >
    > The alert shows me that the value has changed (I can also see it change on
    > the page).
    >
    >
    > And here's the c# code from the SaveRecord event on the aspx page:
    >
    > mIntake.CigScore = int.Parse(txt1.Text);
    >
    > When tracing through the code, I see that txt1.Text still equals the value
    > that was originally loaded into the page.
    >
    > Is there a reason why .Net doesn't see the updated value? Anything I can
    > do
    > to change that?
    >
    > Thanks
    >
    Cowboy \(Gregory A. Beamer\), Oct 11, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ibiza
    Replies:
    2
    Views:
    3,956
    ibiza
    Feb 28, 2006
  2. =?Utf-8?B?a2VuIHM=?=

    Javascript changes not saved

    =?Utf-8?B?a2VuIHM=?=, Oct 10, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    286
    Mark Rae
    Oct 12, 2006
  3. =?Utf-8?B?a2VuIHM=?=

    Javascript changes not saved

    =?Utf-8?B?a2VuIHM=?=, Oct 10, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    335
    =?Utf-8?B?a2VuIHM=?=
    Oct 10, 2006
  4. =?Utf-8?B?a2VuIHM=?=

    Javascript changes not saved

    =?Utf-8?B?a2VuIHM=?=, Oct 10, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    279
    =?Utf-8?B?a2VuIHM=?=
    Oct 10, 2006
  5. =?Utf-8?B?a2VuIHM=?=

    Javascript changes not saved

    =?Utf-8?B?a2VuIHM=?=, Oct 10, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    309
    =?Utf-8?B?a2VuIHM=?=
    Oct 10, 2006
Loading...

Share This Page