Solved

Java Script Post Back

Posted on 2010-11-16
7
976 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
  • 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

828 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