Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run Server script from button and return result in a text box.

Status
Not open for further replies.

Ladyhawk

Programmer
Jan 22, 2002
534
AU
Hi all,

How do I run a server script from the onclick event of a button and have the resulting string displayed in a text box of the form with the button on it. I don't really want to reload the form because the user may have entered stuff on there. I just want the result displayed in the text box as if you typed txtBlah.Value = "stuff".
 
Without submitting u'r form u cannot access server. Server will process your data only if u submit it . U vcan still maintain the state as the page was aftering submitting the form and reloading it.
Submit the form to the same page.. do u'r processing ... use some variables which will store the data entered by the user and after all this .. display the data as entered by the user....

Hope this helps..

srinu...
 
Unless...

If you don't want to submit there is a work around. You can embed an iframe in the page and write a seperate asp file that has the server-side script in it. In your onCLick change the location attribute on the iframe to you new file and pass your variables along in the URL as part of the querystring. When the user clicks the button the iframe does the work. Set the onload of the new page to go to the parent of the window(iframe) to the parent(div) to children(0) (textbox) in this case and set the value.

On the fly, so pardon any bugs:
In your main file:
<div>
<input type=&quot;text&quot; name=&quot;myText&quot;>
<input type=&quot;button&quot; onClick=&quot;myFrame.location='newpage.asp?variable=value&variable2=value2'>
<iframe style=&quot;display:none&quot;></iframe>
</div>

Your newpage.asp would do Request.QueryStrings to get the values from the variables, execute whatever server-side script you wanted, then output a blank html doc with:
<html>
<body onLoad=&quot;window.parent.parent.children(0).value = '<%=&quot;whatever_you_want_in_the_textbox&quot;%>';&quot;>
</body>
</html>
 
The IFrame idea should work, but you are still making it harder than it needs to be. The best thing to do for a onClick is to use the client side processing. Let VBScript or Javascript handle it. That way not only can you check the form values and run your event without damaging the values the client has entered, but you are using their processor to do the work taking a load off of your server.
 
The main reason I need to use the server if because I want to run a exe on the server. So client side scripting is kinda out of the question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top