Discussion:
Simulate button click to trigger postback
Brady Kelly
2008-01-24 18:44:33 UTC
Permalink
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
Shawn Wildermuth
2008-01-24 19:08:12 UTC
Permalink
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:DOTNET-***@DISCUSS.DEVELOP.COM] On Behalf Of Brady Kelly
Sent: Thursday, January 24, 2008 1:45 PM
To: DOTNET-***@DISCUSS.DEVELOP.COM
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
Christopher
2008-01-24 19:25:00 UTC
Permalink
Page.GetPostBackEventReference(Control) will get you the correctly
formatted javascript regardless of which version of the fx you use.

--
-Christopher
| AspInsider
http://bluefenix.net
Post by Shawn Wildermuth
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
Sent: Thursday, January 24, 2008 1:45 PM
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® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Brady Kelly
2008-01-24 19:30:21 UTC
Permalink
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();
}
Post by Shawn Wildermuth
-----Original Message-----
From: Discussion of building .NET applications targeted for the Web
Sent: 24 January 2008 09:08 PM
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
Sent: Thursday, January 24, 2008 1:45 PM
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� http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Ryan Heath
2008-01-25 08:21:13 UTC
Permalink
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
Post by Brady Kelly
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();
}
Post by Shawn Wildermuth
-----Original Message-----
From: Discussion of building .NET applications targeted for the Web
Sent: 24 January 2008 09:08 PM
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
Sent: Thursday, January 24, 2008 1:45 PM
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
Brady Kelly
2008-01-25 08:52:23 UTC
Permalink
It turned out I was refreshing, on the client click, before the server click
saved the record and closed the detail screen. A simple refresh of the
frame's src to the same src with a timestamp was the simplest.

How would I call the onclick of btnRefresh from outside the frame that
contains btnRefresh's form?
Post by Ryan Heath
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
===================================
This list is hosted by DevelopMentor� http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Ryan Heath
2008-01-25 10:01:42 UTC
Permalink
Post by Brady Kelly
How would I call the onclick of btnRefresh from outside the frame that
contains btnRefresh's form?
Something like

$('m').contentDocument.$('btnRefresh').click();

if 'm' is an iframe.

// Ryan

p.s.
I am not sure whether the second $ will work or not, maybe you should
replace it with an explicit call to getElementById

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

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