ASP.NET Web Controls >> Div and code behind on click event

by Ken Nipper » Tue, 07 Jun 2005 04:08:01 GMT

I am trying to use a div as a quasi button and need to use server side
code to navigate. Any ideas on how to accomplish this?


ASP.NET Web Controls >> Div and code behind on click event

by Brock Allen » Tue, 07 Jun 2005 06:09:36 GMT

You can build a custom control and implement IPostBackEventHandler. The IPostBackEventHandler.RaisePostBackEvent
will get called when your custom control causes a postback. It will cause
a postback when you execute the javascript returned from Page.GetPostBackClientEvent.
So attach the returned javascript to your div's onclick. Here are some MSDN
docs to get you started:


ASP.NET Web Controls >> Div and code behind on click event

by Ken Nipper » Wed, 08 Jun 2005 21:02:49 GMT

Thanks for the info. This helped a lot.


Similar Threads

1. Fire Code behind code AND Javascript code associated to a Button Click Event

I have a button that opens a new Window (some kind of search-window), which is fired using JavaScript (btnSearch.Attributes["onclick"]=".....";)
Now I need to run some code behind code BEFORE this JavaScript runs. I tried to define another Button with an EventHandler associated, and from this (after doing my code) fire ''. But I can't make it work.
I tried
private void Button1_Click(object sender, System.EventArgs e


but unfortunately the browser says that this element is not valid
Am I on the right way or are there better options to do what I try to accomplish 
Thanks for any help

2. Changing div background-image with code behind - Asp.Net

3. using code behind to change the innerhtml of a client side div

I have the following Ticker in a DIV that I was able to place on the top of 
my page using javascript - 'webticker_lib.js' - it works just as I wish...

If I make the DIV runat="server" obviously, the javascript stops working.

My intent is to have a page where some administrative users can type text in 
a textbox, click a button and whatever text they typed would be captured in 
the innerhtml of this DIV 

Seems fairly simple, but my client-side experience is still 'beginner'

How can I do this - or something more efficient?  (the Div is below as well 
as the javascript - webticker_lib.js)

<DIV ID="TICKER" STYLE="overflow:hidden; width:1000px"  
onmouseover="TICKER_PAUSED=true" onmouseout="TICKER_PAUSED=false">
    <script type="text/javascript" src="webticker_lib.js" 

// WebTicker by Mioplanet

TICKER_CONTENT = document.getElementById("TICKER").innerHTML;
TICKER_STYLE = "font-family:Arial; font-size:12px; color:#444444";


function ticker_start() {
	var tickerSupported = false;
	TICKER_WIDTH = document.getElementById("TICKER").style.width;
	var img = "<img src=ticker_space.gif width="+TICKER_WIDTH+" height=0>";

	// Firefox
	if (navigator.userAgent.indexOf("Firefox")!=-1 || 
navigator.userAgent.indexOf("Safari")!=-1) {
		document.getElementById("TICKER").innerHTML = "<TABLE  cellspacing='0' 
cellpadding='0' width='100%'><TR><TD nowrap='nowrap'>"+img+"<SPAN 
width='100%'> </SPAN>"+img+"</TD></TR></TABLE>";
		tickerSupported = true;
	// IE
	if (navigator.userAgent.indexOf("MSIE")!=-1 && 
navigator.userAgent.indexOf("Opera")==-1) {
		document.getElementById("TICKER").innerHTML = "<DIV nowrap='nowrap' 
style='width:100%;'>"+img+"<SPAN style='"+TICKER_STYLE+"' ID='TICKER_BODY' 
		tickerSupported = true;
	if(!tickerSupported) document.getElementById("TICKER").outerHTML = ""; else {
		document.getElementById("TICKER").scrollLeft = TICKER_RIGHTTOLEFT ? 
document.getElementById("TICKER").scrollWidth - 
document.getElementById("TICKER").offsetWidth : 0;
		document.getElementById("TICKER_BODY").innerHTML = TICKER_CONTENT;

function TICKER_tick() {
	if(!TICKER_PAUSED) document.getElementById("TICKER").scrollLeft += 
	if(TICKER_RIGHTTOLEFT && document.getElementById("TICKER").scrollLeft <= 0) 
document.getElementById("TICKER").scrollLeft = 
document.getElementById("TICKER").scrollWidth - 
	if(!TICKER_RIGHTTOLEFT && document.getElementById("TICKER").scrollLeft >= 
document.getElementById("TICKER").scrollWidth - 
document.getElementById("TICKER").scrollLeft = 0;
	window.setTimeout("TICKER_tick()", 30);

4. div - dynamic id - code behind - Asp.Net

5. Custom control fires event but ignores some code in the code behind file

I do not quite understand the question. I will merely point out that
most programming problems happen for a reason. Code works the way it is
supposed to. When it does not it is because we do not understand all of
things involved or understand what we've have told it to do actually

6. Code Behind vs. no code behind: error

7. Non-code behind to code behind


I have a non code behind web form done previously. How can I turn it into a 
web form with an associated code behind file?



8. 'Select' control problem using code behind class to trap 'Submit' button click - ASP.NET Web Controls