Solved

Java Script Post Back

Posted on 2010-11-16
7
986 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:JCWEBHOST
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 13

Expert Comment

by:dsmile
ID: 34144371
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
 

Author Comment

by:JCWEBHOST
ID: 34144385
ok can you show me how to do the first one please
0
 

Author Comment

by:JCWEBHOST
ID: 34144481
Please Help, and explain what you said?
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 13

Expert Comment

by:dsmile
ID: 34144523
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
 
LVL 18

Expert Comment

by:carlnorrbom
ID: 34144798
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
 

Author Comment

by:JCWEBHOST
ID: 34145079
they is no update panel
0
 
LVL 18

Accepted Solution

by:
carlnorrbom earned 500 total points
ID: 34145153
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

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question