How to initiate a postback in a function?

G

Guest

I would like to initiate a postback after I have finish executing some codes
in a dynamically created button_click event. Do anyone know? Please help!!!
Thanks
 
E

Edwin Knoppert

<script language=javascript>
function hello(){ <%=
Page.ClientScript.GetPostBackEventReference(Me.cmdHello, "")%> }
</script>
 
W

Wouter van Vugt

Hi Edwin,

do something like you posted above:

<script runat="server">
protected override void OnLoad(EventArgs e)
{
string script = "function CustomPostback(){ " +
Page.ClientScript.GetPostBackEventReference(this, null) + "
}";
Page.ClientScript.RegisterClientScriptBlock(
GetType(), "MyScript", script, true);
base.OnLoad(e);
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" onclick="CustomPostback();" />
</div>
</form>
</body>
</html>

This is ASP.NET 2.0 code, in ASP.NET 1.1, the methods can be found on
the Page class, e.g. Page.RegisterClientScriptBlock.

Grtz, Wouter
Trainer - Info Support - www.infosupport.com
www.dive-in-it.nl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top