Solved

Java Script Post Back

Posted on 2010-11-16
7
969 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
alert before form submission 6 27
Run time Error 4 34
Interview question Javascript, database 11 18
two layers of simple javascript validation 2 10
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

943 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

10 Experts available now in Live!

Get 1:1 Help Now