Click to See Complete Forum and Search --> : I don't want a postback on a button click


Arthur
February 23rd, 2005, 10:24 AM
Hello,

I have an ASP button (rendered as <input type=submit>), and when I click it, it does a postback to the server.
I would like to do some client side stuff, which I dynamically create and put in "Attributes". I don't want to the button to do a postback when clicked.

To avoid a postback I tried an HtmlButton instead like this:

<BUTTON id="myButton" value="ClickMe"></BUTTON>

In ASP:

Declared a HmlButton myButton and in a postback event handler I want to fill the button like this

myButton.Attributes.Add("onclick", "DoMyDynamicallyFormattedStuff");

However I get a nullrefrenceException on myButton.

Does anyone how I can create a button, with dynamically added attributes that does not perform a postback?

Arthur

jcmorin
February 24th, 2005, 05:27 PM
Hello Arthur,

To access any control from server side the control must have a Runat="Server" attribute.

This:
<BUTTON id="myButton" value="ClickMe"></BUTTON>

Should be:
<BUTTON id="myButton" value="ClickMe" runat="server"></BUTTON>