Posts Tagged ‘Javascript’

Sometimes we require to invoke postback of a control but cannot set AutoPostBack property to true. In such case we can make use of __doPostBack method of Javascript. 

I`ll Give you A Simple Example How You Can Do This..


Include these 3 tags into your .aspx page.

<input type=”hidden” name =”__EVENTTARGET” value =”” />
<input type=”hidden” name =”__EVENTARGUMENT” value =”” />
<a id=”LButton3″ href=”javascript:__doPostBack(‘Button2′,’ ‘)”>LinkButton</a>

Here we have on anchor tag we want a server side event to fire on click of this link.

Now write this javascript function . Form1 is the id of your form.

<script type=”text/javascript”>

function __doPostBack(eventTarget, eventArgument) {
document.Form1.__EVENTTARGET.value = eventTarget;
document.Form1.__EVENTARGUMENT.value = eventArgument;


Now, Lets talk about Server Side operations . You Have To Write this code in your .cs file

protected void Page_Load(object sender, EventArgs e)
if (Request.Form[“__EVENTTARGET”] == “Button2”)
//fire event
Button2_Click(this, new EventArgs());

protected void Button2_Click(object sender, EventArgs e)
Response.Write(“postback event fired”);


this will fire your Button2_Click event..

This Is Basic , Now You Can Modify This Code as You Want 🙂

Hope This Post Will Help you Somehow . . :) . Feel Free To Ask Anything You Need.

Waiting For Your Valuable Feedback.