Re: Simulate button click to trigger postback

Ryan Heath <[email protected]> Fri, 25 Jan 2008 09:21:13 +0100
Newsgroups gmane.comp.windows.devel.dotnet.web
Message-ID <[email protected]>
You should inspect what javascript is called at the onclick of the btnRefresh.
Then call that code in your refreshMainForm

It will have more or less the form like
WebForm_DoPostBackWithOptions(new
WebForm_PostBackOptions("ctl00$btnRefresh", "", true, "", "", false,
false));

or just call the onclick of the btnRefresh, which is probably better
for code maintenance.

// Ryan

On Jan 24, 2008 8:30 PM, Brady Kelly <[email protected]> wrote:
> I'm currently setting a flag and calling submit(), which causes a postback.
> Now I have the mysterious problem that when my Page_Load fires, and calls
> the refresh code, nothing happens, but when I click the Refresh button
> straight after that, the page does refresh.
>
> My code follows (the '$' function is a dirty shorthand for
> GetElementsByTagName).  In both cases InitGrid is called, but the page only
> refreshes when btnRefresh is clicked.
>
>
> function refreshMainForm() {
>    var myForm = $('m').contentDocument.forms[0];
>    debugger;
>    if (myForm.isRefresh)
>    {
>        myForm.isRefresh.value = "y";
>        myForm.submit();
>    }
> }
>
> protected void Page_Load(object sender, EventArgs e)
> {
>    if ((!IsPostBack) || (isRefresh.Value == "y"))
>    {
>        isRefresh.Value = "";
>        lblFormName.Text = MyController.FormName;
>        InitGrid();
>    }
> }
>
> protected void btnRefresh_Click(object sender, ImageClickEventArgs e)
> {
>    InitGrid();
> }
>
>
> > -----Original Message-----
> > From: Discussion of building .NET applications targeted for the Web
> > [mailto:[email protected]] On Behalf Of Shawn Wildermuth
> > Sent: 24 January 2008 09:08 PM
> > To: [email protected]
>
> > Subject: Re: [DOTNET-WEB] Simulate button click to trigger postback
> >
> > Can't you just call the PostBack Javascript method that is created
> > ASP.NET
> > pages?  View the source of the page and see what happens when the
> > button is
> > clicked.
> >
> > Thanks,
> >
> > Shawn Wildermuth
> > http://adoguy.com
> > http://wildermuthconsulting.com
> > Microsoft MVP (C#), MCSD.NET, Author and Speaker
> >
> > The Silverlight Tour is coming to a city near you!
> >
> > -----Original Message-----
> > From: Discussion of building .NET applications targeted for the Web
> > [mailto:[email protected]] On Behalf Of Brady Kelly
> > Sent: Thursday, January 24, 2008 1:45 PM
> > To: [email protected]
> > Subject: [DOTNET-WEB] Simulate button click to trigger postback
> >
> > I have tried many ways of forcing a page refresh from within
> > Javascript, but
> > my learned colleagues of implemented some sort of URL uniqueness scheme
> > to
> > prevent caching and I think this is messing me around.  I have a
> > Refresh
> > button on the page for a manual refresh, so how do I go about
> > triggering the
> > server side Click event for that button?
> >
> >
> > ===================================
> > This list is hosted by DevelopMentor.  http://www.develop.com
> >
> > View archives and manage your subscription(s) at
> > http://discuss.develop.com
> >
> > ===================================
> > This list is hosted by DevelopMentor.  http://www.develop.com
> >
> > View archives and manage your subscription(s) at
> > http://discuss.develop.com
>
> ===================================
> This list is hosted by DevelopMentor(R)  http://www.develop.com
>
> View archives and manage your subscription(s) at http://discuss.develop.com
>

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com