Java Script Post Back

Hey Guys, i have an external JavaScript and i want it to give me a post back so my values are set and will not change if i continue with any other postback.

here is an exsample:

this is my code in the external javascript:

document.getElementById(CostCalculaterEuroTotalThesisCost).value =(TotalThesisCost / Euro).toFixed(2);

which is "CostCalculaterEuroTotalThesisCost)." is a asp Label, but when i select a dropdownlist with a postback the Label goes back to 0.00


so i need something that will give me a postback in a javascript to save the information to the Label


I am using an onkeyup method on a textbox to chage the label
JCWEBHOSTAsked:
Who is Participating?
 
carlnorrbomConnect With a Mentor Commented:
Hi,

Then if the textbox is not nested inside another control (regular panel?!?) you should be able to reference it directly from code behind like:
CostCalculaterEuroTotalThesisCost.Text = Request.Params("__EVENTARGUMENT").ToString()

Open in new window


Even easier.

/Carl.
0
 
dsmileCommented:
There're at leats 2 ways to achieve that:

1. onkeyup of the textbox you use to change label's value, add postback process so that new cost is stored

2. along with label's value changing, store that data to a hidden field in the form, and then update it to DB on postback.

If the value you use to change label's value is not meant to be stored in DB, then you have to post it back to server, and then pass it again to the screen so that you can use it.
0
 
JCWEBHOSTAuthor Commented:
ok can you show me how to do the first one please
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
JCWEBHOSTAuthor Commented:
Please Help, and explain what you said?
0
 
dsmileCommented:
I just base on your provided info


"which is "CostCalculaterEuroTotalThesisCost)." is a asp Label, but when i select a dropdownlist with a postback the Label goes back to 0.00"
--> then it means you already knew how to postback using javascript.


"I am using an onkeyup method on a textbox to chage the label"
--> then it means you already had the js that handles onkeyup event.

Then you implement like this:
1. add the code that do postback like the one you use in dropdownlist to the inner of function that handles onkeyup event .
2. on server side, you store the posted back data to db
3. on client side, always use the data from db to display at CostCalculaterEuroTotalThesisCost
0
 
carlnorrbomCommented:
Hi,

Is the textbox inside an updatepanel? If not it will be a not so pleasant experience if the page is to post back to the server on each onkeyup?

Other than that you can quite easily do like this:
    <script language="javascript" type="text/javascript">
        function storeTextBoxValue(id, value) {
            __doPostBack(id, value);
        }
    </script>

Open in new window

And for the textbox add:
 onkeyup="storeTextBoxValue(this.id, this.value);"

Open in new window


And in the Page_Load event in code behind do a check like:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        If Page.IsPostBack Then
            If String.Compare(Request.Params("__EVENTTARGET").ToString(), TextBox1.ClientID.ToString()) = 0 Then
                'Means the page have posted back to the server and the event target (control who initiated the postback) is txt1
                Dim CostCalculaterEuroTotalThesisCost As Label = CType(UpdatePanel1.FindControl("CostCalculaterEuroTotalThesisCost"), Label)
                CostCalculaterEuroTotalThesisCost.Text = Request.Params("__EVENTARGUMENT").ToString()
            End If
        End If
    End Sub

Open in new window


This short example assumes the textbox is nested inside an udpatepanel (UpdatePanel1) with ID="TextBox1".

/Carl.
0
 
JCWEBHOSTAuthor Commented:
they is no update panel
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.