views:

256

answers:

2

I have an ASP.NET page with a cs script file to take in data and then post it to another site.

On the site I am using a regular HTML form with asp:TextBox and asp:HiddenField values throughout it to collect/hold data. The problem I'm having is that some of the key data on it have to be hashed and salted before they are posted to a different site.

I have a method to do this, it works fine, but it is attached to the submit button's OnClick attribute, its an asp:Button currently with a postbackurl set. This apparently means that it gets skipped when it goes to the new page which is not what i want.

I'm still fairly new to web development so is there a way to run a method right before the page is submitted, or will I have to run the method everytime a field that would effect the hash is changed ?

+1  A: 

If your hashing method written in javascript and you're calling it at your button's onclick client side event. it should run before your form posted. Using form's onsubmit event might be an alternative.

But if you're talking about server side hashing function that sets the hidden control's value you should use Server.Transfer after your hashing method. Because the button with PostBackUrl property doesn't postback the page itself.

Canavar
It was in C#, which probably was a problem. But the text boxes are in asp:TextBox form. Do i have to change them all to regular HTML code or is there a way for javascript to access/set the data in them?
Jared
No, if it's at server side, you can not get the hidden fields' values, too. because if you use PostBackUrl property, the current page is not post back to itself. so you can not set your fields. as I said, use Server.Transfer instead.
Canavar
Yea, I don't want to post back to the server because that would put the sensitive info they type on it out into the open. Trying to make it 1 step from the form to the processing page, which happens to be someone else's and in php =\
Jared
Yes I understand, but in this way you can't make your server side code run. Maybe you can make an AJAX call, and get the hashed data of yours ? then post to the other application ?
Canavar
A: 

You might want to look at the Page.ClientScript.RegisterOnSubmitStatement

This will be a way to execute some javascript as the form is submitting.

BillRob