This is probably simple but I'm not seeing why this won't work. I have button on a form declared as:
At the top of the content control, I have this:
Basically, I want the button to display the confirm and if the result is true, then I would like to process the code behind for the cancel button.
However, when I run this, and click OK in the confirmation dialog box, I get "Microsoft JScript runtime error: 'document.getElementById(...)' is null or not an object".
Any ideas on how to resolve this?
Thanks,
Dennis
<asp:button ID="CancelButton" runat="server" OnClick="CancelButton_Click" Text="Cancel" CssClass="btnNormal" OnClientClick="CancelTrainingSessionDialog(this); return false;"/> |
<telerik:RadWindowManager ID="RadWindowManager1" runat="server"> |
</telerik:RadWindowManager> |
<telerik:RadCodeBlock ID="JavascriptRadCodeBlock" runat="server"> |
<script type="text/javascript"> |
var cancelMessage = "Are you sure"; |
var cancelTitle = "Cancel Title"; |
function CancelTrainingSessionDialog(cancelButton) { |
radconfirm(cancelMessage, CancelTrainingSessionCallback); |
} |
function CancelTrainingSessionCallback(arg, cancelButton) { |
if (arg == true) { |
document.getElementById("CancelButton").click(); |
} |
} |
</script> |
</telerik:RadCodeBlock> |
Basically, I want the button to display the confirm and if the result is true, then I would like to process the code behind for the cancel button.
However, when I run this, and click OK in the confirmation dialog box, I get "Microsoft JScript runtime error: 'document.getElementById(...)' is null or not an object".
Any ideas on how to resolve this?
Thanks,
Dennis
13 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 17 Nov 2009, 09:47 AM
Hello Dennis,
You can refer to the following code library submission inorder to allow the radconfirm window to simulate the blocking of the execution thread while waiting for user's confirmation:
Block the execution thread with radconfirm
Hope this helps..
Princy
You can refer to the following code library submission inorder to allow the radconfirm window to simulate the blocking of the execution thread while waiting for user's confirmation:
Block the execution thread with radconfirm
Hope this helps..
Princy
0
Hi Dennis,
I believe that the problem here is due to the fact that the button is in an iNamingContainer and you should use the ClientID of the button instead.
If you want to avoid the postback and you are using RadAjax, you could also consider using ajaxRequestWithTarget() for making the call to the server.
Kind regards,
Georgi Tunev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I believe that the problem here is due to the fact that the button is in an iNamingContainer and you should use the ClientID of the button instead.
If you want to avoid the postback and you are using RadAjax, you could also consider using ajaxRequestWithTarget() for making the call to the server.
Kind regards,
Georgi Tunev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0

Dennis
Top achievements
Rank 1
answered on 17 Nov 2009, 03:23 PM
Princy and Georgi, thank you both for your help.
Georgi,
I have changed my callback method to closely resemble the one you suggested in this forum posting (http://www.telerik.com/community/forums/aspnet-ajax/window/radconfirm.aspx) dated Jul 6. Here is what my function looks like now:
When I the confirm appears, clicking cancel dismisses it appropriately. Clicking OK does nothing (no errors, but the confirmation window continues to display).
Any thoughts as to why this isn't working?
Georgi,
I have changed my callback method to closely resemble the one you suggested in this forum posting (http://www.telerik.com/community/forums/aspnet-ajax/window/radconfirm.aspx) dated Jul 6. Here is what my function looks like now:
function CancelTrainingSessionCallback(arg, cancelButton) { |
if (arg == true) { |
document.getElementById("<%= CancelButton.ClientID %>").click(); |
} |
When I the confirm appears, clicking cancel dismisses it appropriately. Clicking OK does nothing (no errors, but the confirmation window continues to display).
Any thoughts as to why this isn't working?
0
Hello Dennis,
To be able to help I need to have a better view over your exact setup and logic. Please open a support ticket and send me a small sample project that shows the problem so I can investigate further. Once I receive that project, I will check it and get back to you with the solution.
Sincerely yours,
Georgi Tunev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
To be able to help I need to have a better view over your exact setup and logic. Please open a support ticket and send me a small sample project that shows the problem so I can investigate further. Once I receive that project, I will check it and get back to you with the solution.
Sincerely yours,
Georgi Tunev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0

Dennis
Top achievements
Rank 1
answered on 18 Nov 2009, 08:48 PM
Thank you Georgi. I will need to create the sample project. I will send it to you when ready.
0
OK Dennis,
I will expect your ticket - just add a reference to this forum thread as well - I will update it once we find a solution.
All the best,
Georgi Tunev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I will expect your ticket - just add a reference to this forum thread as well - I will update it once we find a solution.
All the best,
Georgi Tunev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0

Dennis
Top achievements
Rank 1
answered on 23 Nov 2009, 03:59 PM
Thank you Georgi. I have created a support ticket with the subject "Forum follow up sample project for Georgi Tunev". It is ticket 261140.
Thanks for all of your help,
Dennis
Thanks for all of your help,
Dennis
0
Accepted
Hi Dennis,
I just answered your support ticket and sent you the solution - the project helped me a lot to understand what was going on :)
For convenience I am pasting my reply below:
Thank you very much for the sample project - now I see what the problem is. I was under the impression that the button that you click programatically is a hidden button on the page that you use to execute the server-side function that you want, but now I see that this is actually the same button (Cancel).
What happens with your current code is:
Note: In both cases I changed the OnClientClick event handler to return the result from the JavaScript function and I cancel the postback there.
e.g.
Approach #1 - Use ajaxRequestWithTarget with the RadAjaxPanel
Approach #2 - use __doPostBack() instead of Ajax request:
I hope this helps.
Sincerely yours,
Georgi Tunev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I just answered your support ticket and sent you the solution - the project helped me a lot to understand what was going on :)
For convenience I am pasting my reply below:
Thank you very much for the sample project - now I see what the problem is. I was under the impression that the button that you click programatically is a hidden button on the page that you use to execute the server-side function that you want, but now I see that this is actually the same button (Cancel).
What happens with your current code is:
- You click on the button and the radconfirm dialog appears
- You click OK in the confirm dialog which calls the client callback function
- The client callback function programatically clicks that same Cancel button again
- The radconfirm dialog appears again, because the button's OnClientClick is executed for the second time.
Note: In both cases I changed the OnClientClick event handler to return the result from the JavaScript function and I cancel the postback there.
e.g.
<
asp:Button
ID
=
"CancelButton"
runat
=
"server"
OnClick
=
"CancelButton_Click"
Text
=
"Cancel"
CssClass
=
"btnNormal"
OnClientClick
=
"return CancelTrainingSessionDialog(this);"
/>
Approach #1 - Use ajaxRequestWithTarget with the RadAjaxPanel
var
cancelMessage =
"Are you sure"
;
var
cancelTitle =
"Cancel Title"
;
function
CancelTrainingSessionDialog(cancelButton)
{
radconfirm(cancelMessage, CancelTrainingSessionCallback);
//cancel the postback here
return
false
;
}
function
CancelTrainingSessionCallback(arg, cancelButton)
{
if
(arg ==
true
)
{
//document.getElementById("<%= CancelButton.ClientID %>").click();
var
panel = $find(
"<%=TrainingQuestionsAjaxPanel.ClientID%>"
);
panel.ajaxRequestWithTarget(
"<%= CancelButton.UniqueID %>"
,
""
)
}
}
Approach #2 - use __doPostBack() instead of Ajax request:
var
cancelMessage =
"Are you sure"
;
var
cancelTitle =
"Cancel Title"
;
function
CancelTrainingSessionDialog(cancelButton)
{
radconfirm(cancelMessage, CancelTrainingSessionCallback);
//cancel the postback here
return
false
;
}
function
CancelTrainingSessionCallback(arg, cancelButton)
{
if
(arg ==
true
)
{
//document.getElementById("<%= CancelButton.ClientID %>").click();
//note that when calling __doPostBack(), the UniqueID should be used, instead of ClientID
__doPostBack(
"<%= CancelButton.UniqueID %>"
,
""
);
}
}
I hope this helps.
Sincerely yours,
Georgi Tunev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0

Dennis
Top achievements
Rank 1
answered on 24 Nov 2009, 01:59 PM
Georgi,
Thank you so much for all of your help. Made the couple of minor changes and implemented approach #2. Works like a charm.
Thanks!!
Thank you so much for all of your help. Made the couple of minor changes and implemented approach #2. Works like a charm.
Thanks!!
0

Hardik
Top achievements
Rank 1
answered on 18 Oct 2010, 09:06 PM
Can you please let me know , what modifications are required for the later approach....
0

Andrew
Top achievements
Rank 1
Veteran
Iron
answered on 03 Feb 2011, 06:48 PM
but how would you do Approach #2 if the button that is being clicked is in a grid
as I can't do this
as I can't do this
"<%= CancelButton.UniqueID %>"
0
Hi Andrew,
Please provide more details about your exact setup. What is this button and when it is clicked? If possible, it will be best to send (in a support ticket) a sample project that shows your exact setup, so we can provide you with the most appropriate solution.
Kind regards,
Georgi Tunev
the Telerik team
Please provide more details about your exact setup. What is this button and when it is clicked? If possible, it will be best to send (in a support ticket) a sample project that shows your exact setup, so we can provide you with the most appropriate solution.
Kind regards,
Georgi Tunev
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0

Andrew
Top achievements
Rank 1
Veteran
Iron
answered on 04 Feb 2011, 03:26 PM
thanks but I took a different path and it is no longer an issue