Solved

Java Script Post Back

Posted on 2010-11-16
7
967 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now