Click to See Complete Forum and Search --> : Dynamically Controling HTML Tags


Serin
11-11-2005, 09:21 PM
I have an image button that has a property that looks like so:

btnAdd[i].OnClientClick = "<% addToCart(product); %>";

I want this button to run the C# function; however, it translates into html like this:

onclick="&lt;% addToCart(product); %>;"

How can I get this to work correctly?

-Serin

Giskard
11-12-2005, 08:45 AM
It looks like you're trying to run the ASP on the client side. What you need to do is have the image button redirect to a page that runs the "addToCart()" function and reloads the current page. For example:

onclick="window.location='AddToCart.asp?productID="+frmName.productID+"'"

Then have the AddToCart.asp page look like:

<%
addToCart(Request("productID"))
Response.redirect("OldPageName.asp")
%>

Or you could have the current page handle a postback by placing this at the top of your current page (and having the image reload the current page:
<%
if Request("ProductID") <> "" then addToCart(Request("productID"))
%>

Hope this helps