Hi,
Below is my scenario:
->I have two user controls, ucA and ucB and a page mypage.aspx.
->ucA is being used in ucB and ucB is displayed in mypage.aspx.
Both user controls have update panels in them.
->I have two dropdown controls, drpl1 and drpl2 on ucB. And both
dropdown list controls's autopostback property set to true. If I pick
drpl1 then drpl2 gets update. When drpl2 gets picked there is another
dropdown (autopostback=false) and that gets filled based on drpl2
selected value.
So by the time the mypage.aspx loads, based on the business rules
either drpl1 or drpl2 gets focus and having focus is a must.
Now, say for instance, the drpl2 (most of the times drpl2 gets
focus) gets focus when the page loaded. With out changing the option
in the drpl2, if I click any where on the page then it does a
postback. I would like to emphasis once again that I am not change
option (i.e selectedIndexChanged shouldn't fire because I am not
changing the option) in the drpl2 but it still does a postback.
So, to see what kind of post back it is doing I put this code in
my page_load
If Page.IsPostBack Then
If
(ScriptManager.GetCurrent(Me.Page).IsInAsyncPostBack) Then
Dim s As String = "There is an Async post
back"
Else
Dim s1 As String = "There is no async post
back"
End If
End If
and when i debugged I figured that it is doing an
IsInAsyncPostBack.
So upon searching, came across the PageRequestManager clss and now
trying to cancel the AsncPostBack that was taking place above.
Here is how I am doing it:
in mypage.aspx I put this javascript code
function pageLoad() {
var manager =
Sys.WebForms.PageRequestManager.getInstance();
if (manager.get_isInAsyncPostBack()) {
alert('This is in Asyncpostback');
//manager.add_beginRequest(cancelPostBack);
manager.add_initializeRequest(cancelPostBack);
}
function cancelPostBack(sender, args) {
alert('Cancelling auto post back')
args.set_cancel(true);
}
}
and loaded the mypage.aspx and tried to remove the focus by
clicking any where on the page or any get focus to any other text box
and tried to type in some text in it and I lost the typed text because
of the page refresh.
When the page loads for the first time, from the above javascript
it always fired the alert('This is in Asyncpostback'); never fired the
alert('Cancelling auto post back'); box!
(Note: It fired the alert('This is in Asyncpostback'); box after
executing my page_load code. That means it for some reason doesn't go
to the cancelPostBack event at all)
But after the first trail, and in all the subsequent trails of
loosing focus and changing the options in the drpl2 it always fired
the alert('Cancelling auto post back'); box and it cancelled the
postback.
Now my issue is I do not want any kind of post back happen when
the mypage.aspx loads for the first time and when the drpl2 lost its
focus. And by theory it shouldn't postback because I am not changing
the option in the drpl2 am I just removing the foucs.
I made a small test in another webpage with a dropdown (with
autopost=true and also with OnSelectedIndexChanged="somethingchanged")
and it doesn't postback just because it lost the focus. It only does
when I change the option.
Hope the explanation is understandable. Any idea what is going on
and what might be causing to post the page back when the drpl2 lost
its focus when the page loads for the first time?
Thanks in advance, I am curious to see what might be causing it
but couldn't figure out.
Thanks in advance,
L
--
You received this message because you are subscribed to the Google
Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML
Web Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en
or visit the group website at http://megasolutions.net