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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript using c#

Status
Not open for further replies.

quinnipiac0807

Programmer
Oct 25, 2004
38
US
This should be a fairly easy question and I'm not sure why I can't get this to work. I have an asp:button on my page and a javascript function in the html. I need to call this funtion using c# on the btnCancel_Click() event. I'll show you the funtion and the code I'm using but for some reason it's not working.

Javascript funtion. (This works)
<script language="javascript">
function WhereTo()
{
location.href == history.back(-1);
}
</script>

I'm calling it using this line.
Response.Write("<script language=javascript>javascript:WhereTo()</script>");

For some reason this doesn't work. Any suggestions.

Thanks in advance.
 
I'm telling you it looks so easy, but when I use that line I get an error that says, "Object Expected". I'm confused.
 
Ok. I use "Response.Write()" sometimes, too, and it works. Note that I added the semicolon after the function call. You did that, right?

Another mechanism is to use the Page.RegisterStartUpScript() method in you btnCancel_Click method.

So the first time you load the page, no script runs. The user clicks the cancel button, which registers a startup script. Then when the page returns, the script runs.

Try that instead of Reponse.Write(). If you still have problems, it's probably the JavaScript, not the C#.



Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top