ASP button OnClick not firing in javascript popup - javascript

I am attempting to submit form data from within a javascript popup window.
The popup opens fine and displays all elements as expected. When I click the asp:button, before inputting anything, it performs required field validation as expected. All of that is working just fine.
The problem I am having is in getting the OnClick to work and submit the form data.
To say I am a beginner to javascript/JQuery is an understatement, so requesting a bit of hand-holding on this one. Thanks in advance for the help.
<asp:Button ID="submitRes" CssClass="button" runat="server" ClientIDMode="Static" Text="Submit This Form Data" OnClick="Submit_Click" />
$( document ).ready(function() {
$(document).on("click", ".divPopupAdd", function(event){
showPopup()
});
function showPopup(){
$("#popup_add").dialog({
show: { effect: "blind", duration: 200 },
resizable: false,
modal: true,
width: 750,
height: 450,
open: function(){
$('#<%=submitRes.ClientID %>').click();
}
});
}
});

Ok, this is how you post back - click a button to run your code behind.
We going to lay this out step by step.
We assume, that you click a button on your form, and it launches the jQuery dialog? Beyond important here that this “is” in fact your flow in this form.
So, I’m going to assume user clicks a button, and the dialog is launched.
(and avoid that document on-ready. Please dump it).
Now the dialog is displayed. In that dialog, we assume user enters data, does whatever, and THEN either clicks a button for ok, or clicks a button to cancel?
Next up:
You CAN NOT do/use an asp.net button for a post back in that dialog. It WILL NOT work – end of story!
And if you did get the post back to work, it would mess up your current page “dom” that is holding the current web page, and also that of the dialog. It just does not work – don’t do it, ok?
(so no post backs in that dialog!!)
But we can still happy make this work!!!
So, how do we setup a button in the dialog?
Lets assume you need to click a button inside the dialog?
Button MUST be client side JavaScript (js).
That button will:
Close the dialog, and THEN do the post back.
So, we thus need this flow:
Display dialog on button click (client side js).
User does whatever in that dialog.
User now clicks on a button (say ok, or cancel).
We CAN and will for the sake of going crazy? We will drop on the form and use standard asp.net buttons. There is really no need to adopt HTML “input” buttons. (You can, but no real need here).
I am going to use BOTH built in jQuery buttons and ALSO two standard buttons in that dialog (the reason is many, but that way YOU can choose either way, and learn this. (boy, do I with someone had laid out how this works for me!!!). So, I going to save you much pain and suffering here.
So, lets start from the top:
Our button code to pop the dialog.
The asp button will be this:
<asp:Button ID="showdialog" runat="server" Text="Show the dialog"
OnClientClick="showpop();return false;"/>
Note close in above!!!!
We use OnClientClick=showpop();return false.
This will thus run js code, and NOT do a post back. The return = false is VERY important here, since if you leave that out, then the standard asp button will post back like it “normally” does. And we break our new rule!! – no post backs inside the dialog!!.
Ok, so that is the button to launch the dialog.
The js code to launch the popup is similar to what you have.
Eg this:
function showpop() {
var mydiv = $('#popdialog');
mydiv.dialog({
autoOpen: false, modal: true, title: 'My cool dialog, width: '30%'
});
// Open the dialog
mydiv.dialog('open');
}
Now, again for this example, we assume that you dropped some standard asp buttons in that dialog. But, OFTEN you want to use the built in dialog buttons. So let’s do BOTH for this example.
So, the above code thus becomes this:
function showpop() {
var mydiv = $('#popdialog');
mydiv.dialog({
autoOpen: false, modal: true, title: 'My cool other page', width: '30%',
position: { my: 'top', at: 'top+150' },
buttons: {
'ok': mycustomok,
'cancel': mycustomcancel
}
});
// Open the dialog
mydiv.dialog('open');
}
Note the two built in buttons we added. (ok, and cancel).
Note how I also broke out the 'setup' and THEN the one line that pops the dialog.
And in our pop up div, we also have two custom buttons. As noted, I am including both custom and built in dialogs. This will take you “hours” to get nice examples of this, and now you can choose either road.
So, our div has some text, and two custom buttons, and a simple text box.
The div looks like this:
<div id="popdialog" runat="server" style="display:none">
<h2>My cool pop dialog</h2>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Button ID="MyOk" runat="server" Text="My custom ok"
OnClientClick="mycustomok();return false;"/>
<br />
<asp:Button ID="MyCancel" runat="server" Text="My custom cancel"
OnClientClick="mycustomcancel();return false;"/>
</div>
The only real thing to note in above is the style=”display:none” for the WHOLE “div”. This will thus hide the div, and it will not display when the page loads.
So, when we click on the button, it will show the dialog. You will see this:
So, we have our two custom buttons, and the two jQuery but in buttons. If you don't want the built in ones then use my first sample code. As I stated, your choice as to which buttons you want, like, or feel to use here. The main point is that BOTH sets of buttons do the SAME thing.
So, for this example, you click “ok”, or “my custom ok”.
Either way? We want our post back to run for that choice.
And for my custom cancel, or the built in cancel, we want code behind (server code) to run for that cancel choice. Do keep in mind you often don't need any code - but JUST the dialog to close and cancel and do nothing.
So, the two js stubs we have for this are:
function mycustomok() {
// first, close the dialog
$('#popdialog').dialog('close');
#('#HiddenOk').click();
}
function mycustomcancel() {
// first, close the dialog
$('#popdialog').dialog('close');
$('#HiddenCancel').click();
}
As noted, if you use BUILT IN buttons for the dialog, then you do NOT need the “close” of the dialog I have above. But your using (we assume) custom buttons, and not the built in jQuery ones.
And as noted, based on either choice, we will do a post back and run code behind. As I stated, the short way, easy way is to drop two hidden buttons on the form, they will look like this, and of course our outside the above div
<asp:Button ID="HiddenOk" runat="server" Text="hidden ok"
style="display:normal"/>
<asp:Button ID="HiddenCancel" runat="server" Text="hidden cancel"
style="display:normal"/>
Note careful (note BEYOND carefull here).
I have display = normal for the two buttons. The reason is that then with the designer you can double click on the button, and write your code behind. When you are DONE and have both code behind stubs written, then change the above display:normal to display:none to hide them. So we left the buttons visible for easy development. Once you wired up the code behind (simply double click on the buttons in the designer), then you are jumped to the code behind editor, and can write that code.
I have this for now:
Protected Sub HiddenOk_Click(sender As Object, e As EventArgs) Handles HiddenOk.Click
Debug.Print("dialog ok code run")
End Sub
Protected Sub HiddenCancel_Click(sender As Object, e As EventArgs) Handles HiddenCancel.Click
Debug.Print("dialgo cancel code")
End Sub
Of course you write whatever you need. As noted, you may well not need any code for the cancel button – you can leave that out of this design if you wish.
So, with the two code subs automatic wired up for you (this is why we all love asp.net forms, right???).
The “click” button trick as noted is rather nice. It solves a LONG list of issues, and does so with great ease.
You get the needed post back.
You get to run your own cute little code stub behind.
You don't have to write up ajax calls to do this!!!
So this follows the whole asp.net design pattern in which you drop buttons on a form, click them, and you get to run that nice little short code behind stub. And it all wired up automatic for you.
Thus in summary:
Don’t try + attempt post backs in the dialog – you REALLY can’t do this.
And you find they don’t work anyway! So buttons on that dialog WILL run “js” code.
you can use asp buttons if you want, just remember the extra return=false part.
If you must set/send some information to the server in that dialog before you close? Well, that is a different question and answer. But the jQuery "ajax" method works REALLY nice, and you can directly call functions in your existing web page code behind, and do so with next to no effort. You don't even have to know how to setup web methods - asp.net will do all the dirty work. but lets leave that example for another day.
Try the above idea - the "click" button trick in js really is the magic key to making this all oh so very easy to write and setup.

If you wish to call the JavaScript popup from Backend side you can use ClientScript.RegisterStartupScript
Syntax:
ClientScript.RegisterStartupScript(Type type, string key, string script, bool addScriptTags)
Parameters
Type: The type of the startup script to register. This is of type 'Type'
key: The key of the startup script to register. This is of type String
script: The startup script literal to register. This is of type String
addScriptTags: A Boolean value indicating whether to add script tags. This is of type bool - true or false.
You can write like this:
protected void Button_clilck(Object sender, EventArgs e){
ClientScript.RegisterStartupScript(GetType(), "Key","showPopUp(),true);
}
And if you want to call your pop up method from Front End side you can simply call the JS method in asp:button by writing OnClientClick
<asp:Button ID="submitRes" CssClass="button" runat="server" ClientIDMode="Static" Text="Submit This Form Data" OnClick="Submit_Click" OnClientClick="showPopup" />

Related

How can prevent postback page in the case of using both a JavaScript and a C# method on a button?

This is an ASP.NET C# question.
<script>
function buttonfunc() {
document.getElementById("demo").innerHTML = "js work";
}
</script>
<form id="form1" runat="server">
<div>
<p id="demo"></p>
<asp:Button ID="UpdateButton" runat="server" Text="Update"
OnClick="UpdateButton_Click" OnClientClick="buttonfunc()"; return false;/>
</div>
</form>
protected void UpdateButton_Click(object sender, EventArgs e)
{
Response.Write("cs work");
}
In the case of using both a JavaScript and a C# method on a button, how can we stop postback page and display two lines of text at the same time (if possible, without using AJAX)?
The way this works is rather handy.
While that button can have both a client side event, and a server side event?
If the client side js code/event returns false, then the server side event will not trigger. This is ideal for say prompting a user to delete a record, or to perform some operation that you require a "confirm" for.
so, take this button:
<asp:Button ID="cmdDel" runat="server" Text="Delete record"
CssClass="btn"
OnClick="cmdDel_Click"
OnClientClick="return DelConfirm()" />
<script>
function DelConfirm() {
return confirm("Really delete this reocrd?")
}
</script>
so, if the js code (client side) returns true, then server button click runs. If client side js code returns false, then server side button does not run.
You would see this for running above:
and display two lines of text at the same time
Hum, that is not clear what you goal here. What 2 lines are you looking to display here?
I mean, either you want/have the server side button event code run, or it does not. As noted, if you return false, then you should not be seeing a post-back. With your sample code, the return false should result in the server side button even NEVER running.
I mean, if you don't do a post-back, then it does not make sense that you can/will have the server side button code run. You require a post-back for this to occur.
Now, you might be able to live with a update panel, and that allows you to define ONLY that part of the web page that will travel up to the server, and run your code. From a user point of view, the page will not appear to have a post back (and you don't actually have a full page post back in this case). The brower scoll bar will not change postion, and you not see the browser "spinner" show a post-back.
So, you drag + drop in the script manager, and then inside of the update paneel, you would have this:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="cmdDel" runat="server" Text="Delete record"
CssClass="btn"
OnClick="cmdDel_Click"
OnClientClick="return DelConfirm()" />
<script>
function DelConfirm() {
return confirm("Really delete this reocrd?")
}
</script>
</ContentTemplate>
</asp:UpdatePanel>
Now, in your code exmaple, place everything inside of the content template, and remove your return false for the client side click. give it a try.
Now, some caution with above. The page life cycle DOES trigger. So, the page load event will fire (like it always does), and then your code stub will run. but to the user, you not see a full page post back. This is often called a "partial page" post-back.
Needless to say, to build a working web forms page, 99% of the time, your page load event that sets up values for controls and does things on the FIRST page load ONLY?
You have the !IsPost back stub in the page load event, so your REAL first time page load code only ever runs one time.
eg:
if (!IsPostBack)
{
// first time page load
// load up grid, some combo boxes etc.
// this code only runs ONE time, on first page load
}

Show confirmation box depending on a hidden field value in Javascript

So a bit of background, I basically have a form where users can change stuff. This form is a bootstrap modal form. I want to display a warning or something when users close the form down if they have made changes to the form. So I thought I would add a hidden field and when things changes on the form (multiple ways this can happen) then I will mark the hidden field with a true value.
I have this working but now all that is left is to create something that will look at the hidden value then show a confirmation box to say something in the realm of "You have made changes and will loose all changes you have made. Would you like to continue?" with a yes, no or ok, cancel buttons.
I though this would be rather simple but for some reason I am struggling and I am not sure why.
My button is create like this
<asp:Button ID="btnX" runat="server" CssClass="close" Text="×" OnClientClick="return confirmClick();" />
I have a server onclick function done in vb.net/c# language is no issue for me I can always translate it like this
Public Sub btnX_Click(sender As Object, e As EventArgs) Handles btnX.Click
CloseModalForm()
End Sub
I also have javascript which would ideally call before the server code
function confirmClick() {
var _changed = document.getElementById('<%=hiddenField.ClientID %>').value;
if (_changed == true) {
alert(_changed);
}
}
However this does not work, I know this is an alert box, I ended up changing it to an alert while trying to get this to work and seeing if i could get a popup message to say true when hidden field is true and for it not to appear when the hidden field is false. I have messed around a lot on this hence why i ended up with alert. But nothing seems to work if i try just
if (alert(_changed)) {
alert(_changed);
}
Then it shows the alert box regardless if the value is a true or false
This seems very simple to me, but I cannot get it to work, which must mean I am missing something which I have not thought about. I have googled how to do if statements with Booleans in case I got that wrong but I cannot see anything wrong in what I am doing. The only other thing is maybe I have completely negated something or miss interpreted the way JS works. Ideally this would be client side rather than server side as this is just a case of asking users if they want to continue. I still need the server side procedure as many more things happen while the modal form closes down.
Any help will be much appreciated.
Ok, first, I assume you have some kind of dialog system you are using. You can try to use bootstrap ones, but they look fantatic, but the markup and really easy way to pop such a dialog with code beyond sucks. So, I suggest using jQuery.UI dialogs. (only issue with jQuery.UI dialogs is the don't look all that great. But, for this example, that's what we going to use.
next up:
We all know that when you drop in a server side button, you can can ALSO add that client side click, and if the routine returns true, then server side click code behind will run. if the js routine returns false, then the server side click button code does not run. This is rather clear, and even your posted code shows this knowledge.
so, for super quick and dirty, and in a hurry, we can, and often do this:
<asp:Button id="cmdDelete2" runat="server" class="btn myshadow" style="margin-left:15px"
type="button"
onclick="cmdDelete_ServerClick"
onclientclick="return confirm('Really delete?')" >
</asp:Button>
Of course for above, we get/see the web browser dialog, and those look REALLY poor!
but, it does work. And thus you get this:
(I am editing a single record in a popup dialog in above)
So, the above use of js confirm() will work. But as you can see, the position and how ugly that dialog box is? Well, its just ugly.
so, we can adopt jQuery.UI dialog. They are much better looking. Of course there are bootstrap ones, and I see quite a few people using sweetAlert (very very nice).
Anyway, ONE BIG HUGE issue with all of these so called "dialog" libraries that look great, function great, and even allow you to set the position of the dialog?
Well, first lets change above to use a jQuery.UI dialog (and I show how in a bit).
So, that rather ugly built in browser dialog now becomes this:
The above is now much nicer. And even better is when you click on that button, the dialog pops RIGHT below and to the right of the dialog.(where you eyes are current looking since you just looked to click on that button!
You can try the above and play with a working demo here:
(it is vb.net + web forms).
Ok, so the next issue to tackle?
All of the current JavaScript (js) frameworks operation on NON BLOCKING code! That means that while confirm() does halt the code, does wait, and then continue when you hit ok (or cancel)? Such blocking code, or halt js code is not allowed anymore. About the only exception is alert() and confirm(). But, they can lock up and freeze the browser code, so they are not recommended anymore.
So, all such 3rd party - and even in the future? Non blocking code is to be used. That means the code is asynchronous.
so, if we call code to pop a dialog? The function will run, display the dialog AND THEN RETURN and EXIT!!!!
but now, that means we can't wait to return the true/false value to the button click (client side).
But, you can use a neat-o little trick!!!
You now (have to) do this:
You run the client side code - return false (server side button click does not run). then when the user makes their choice in the pop dialog, you then set a flag to return true and CLICK the button again!!! This time, the client side routine fires again, but returns true (assuming you hit ok!!!).
So, the code will look like this:
The button looks like this:
<button id="cmdDelete" runat="server" class="btn myshadow" style="margin-left:15px"
type="button"
onserverclick="cmdDelete_ServerClick"
onclick="if (!MyConfirmDel(this)) {return false};" >
<span aria-hidden="true" class="glyphicon glyphicon-trash"> Delete</span>
</button>
Note in above, I did not use a asp:Button, since I wanted the fancy looking bootstrap icon in the button (trash). But, how this works for a button, or asp.net button is the same. But I had to change the comfirm routine a bit, and use the above !MyConfirmDel(this) (the button combines both onclick and onserverclick - and they actually run as one js routine - we can't change that. If you using plain jane asp.net button, then the first markup will work the same.
and the js code now looks like this:
var MyConfirmDelOK = false
function MyConfirmDel(Btn) {
if (MyConfirmDelOK) {
MyConfirmDelOK = false
return true
}
var myDialog = $("#mydelpop");
myDialog.dialog({
title: "Delete Hotel",
width: "26em",
modal: true,
dialogClass: 'ui-widget-shadow',
position: { my: "left top", at: "right bottom", of: Btn },
buttons: {
Delete: function () {
myDialog.dialog('close')
MyConfirmDelOK= true
$(Btn).click()
},
cancel: function () {
myDialog.dialog('close')
}
}
});
Note careful in above. We passed the button, pop the dialog. User makes choice from dialog, and if ok/yes clicked, we set flag = true, and THEN click the button again. The button click runs the client side code again, but this time, it returns true, and thus the server side click code will now run.
If you are using a plain jane asp.net, then this:
<asp:Button id="cmdDelete2" runat="server" class="btn myshadow" style="margin-left:15px"
type="button"
onclick="cmdDelete_ServerClick"
OnClientClick="return MyConfirmDel(this)" >
</asp:Button>
You can try and play with a working demo here for above:
http://www.kallal.ca/WebSite11/WebForm2
Your next idea?
I want to "confirm" or "warn" or have some dialog if they actually changed things?
Don't!!! - just don't!!! If you do that, then EVERY place where you have edits, then for the sake of a consistant UI experiance, then you have to do that.
And it just becomes a "nag" for the users. (and you going to have to write quite a bit of extra client side code to make this work). When you pop a dialog, give them a save button, and a cancel button. Users will then make a habit of hitting the cancel button to go back. They will not care if they accident edit, since they can learn to always hit cancel if they did not mean to edit.
(you can see this UI in action in the above link).
You can have such a confirm dialog - but the less dialogs, the more enjoyable the software becomes. Give the users a cancel or un-do button. Let them decide if they want to bail out - not nag them all day long.

jconfirm does not work on gridview delete functionality

I have a widget that displays information with ObjectDataSource
I have a delete button with a delete command that sends the command directly to ObjectDataSource
I want to show a confirmation before deleting, clicking the confirm button will not do the deletion operation
Please help set up the postback
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkRemove" runat="server" CommandName="delete" OnClientClick="return confirms(this.name,'Do you want to delete the record?');"><img src="/icons/trash.png" title="Delete" /></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
my script:
function confirms(uniqueID,message)
{
var r = false;
$.confirm({
title: 'Alert',
content: message,
buttons: {
confirm: function () {
__doPostBack(uniqueID, '');
},
cancel: function () {
}
}
});
return r;
}
Only the page is refreshed and the record is not deleted
Like most if not all jQuery functions, they are NON BLOCKING. The code does NOT wait.
So, you have to wire up the call to the button AFTER you confirm.
this means:
OnClientClick="return confirms(this.name,'Do you want to delete the record?');"
Has to always return false. Eg:
OnClientClick="confirms(this.name,'Do you want to delete the record?');return false;"
the "confirms" routine WILL NOT WAIT and NOT block the js code.
Few exceptions exist when using js - say alert(), and confirm().
Start down the road of jQuery, or plug-ins, they are async code these days.
You can use the built in JavaScript "confirm" and that will work.
OnClientClick="return confirm(this.name,'Do you want to delete the record?');"
The above works, because the code halts. But jQuery code does not pause or lock up the browser - and for the most part, blocking code is VERY fast being removed from all browser code.
On the other hand, what jConfirm are you using? There is about 500 different ones - some perhaps MIGHT block the code, and perhaps you can have the function return true or false - but then again, we can only guess, right?
I don't see (or know) what "confirm" widget you are using. So, it is a wild guess on my part. And being busy? Don't think I can get back to this post until about 2-3 days from now. And Thanksgiving weekend is coming up. (hint: when you decide to use some js code widget, it would REALLY help if you noted which thinghy you are using).
One approach would be to fire you own post back (and you do seem to be going down that road - I see a postback in your code).
And when you do this, then you have to pick up the postback in the page load event.
(the __DoPostBack will NOT fire the server side (button code behind) events either). However, the post back does occur - and you can thus pick up what you pass with __DoPostBack in the forms on-load event.
So, you could say do this in your page load:
If IsPostBack then
If Request("__EVENTTARGET") = "Some Button Name ID" Then
' the 2nd parm of __DoPostBack can be picked up
' with Request("__EVENTARGUMENT")
End If
End If
So, you passing '' for the post back - you might want to say pass some PK ID or some such (say rowindex). However, you will NOT have any events of the grid view fire (such as row command, or index row changed event). So, you quite much have to pass some PK id or other means to figure out what row you are working on. And then call your routine from above to do whatever you need or want.
You can pass the current PK value with say this:
OnClientClick='<%# "myclick(this.name," + Eval("ID").ToString + "," +
Container.DataItemIndex.ToString + ");return false;" %>' />
In above, I pass all 3 values.
The control name,
a Eval("row from data source") (you can pick up any data column),
and also the grid index row value.
Thus the script for this would be:
function myclick(mycontrolname,MyPKID, MyRowIndex) {
alert('control name = ' + mycontrolname);
alert('My PK ID = ' + MyPKID);
alert('My grid row index = ' + MyRowIndex);
}
so, you can pick which of the 3 values you want to pass in your _DoPostBack command, but you have to catch that _DoPostBack in the forms page load event.
So, in theory, you can pass one of the above 3 values (or all of them). Then you pass back one of the above in your _DoPostBack and pick it up in the forms on-load event as per above.

User confirmation from server side

I want to confirm user to proceed the saving .
Let's say I have two processes , Process-One and Process-Two .
After complete Process-One , I want to show confirmation message box to user to proceed saving Process-Two .
protected void btnSaveProcess_Click(object sender, EventArgs e)
{
..Saving Process-One....
..Saving Process-One Complete....
// here to show "Are you sure you want to Save Process-Two"
//if user confirm "OK" , save Process-Two
//if user "Cancel" , stop and cancel saving Process-Two
}
Actually , I'm a little weak in Javascript . How can I make this process using Javascript ?
TIA :)
Since you said you are not great with javascript, you can try this. Break the process into 2 buttons, first part is done in btnSaveProcess_Click, and now make a second button btnSecond. btnSecond will handle the second part, after btnSaveProcess_Click is done have it trigger the click event of the btnSecond button. when you create the btnSecond set it up with an alert like:
<asp:Button id="btnSecond" Text="2nd Button" CssClass="HideMe" runat="server" OnClientClick="javascript:return confirm('Would you like to proceed?');"/>
this way the 1st button completes and calls the 2nd ones click. that will cause the alert to come up, if the user clicks ok it proceeds to the 2nd ones event, if the user hits no it doesn't continue.
you could use the ASP.NET AJAX Control Toolkit. it has a ConfirmButtonExtender that will show a confirm dialog before triggering the asp.net postback.
if you want some thing more lightweight you could add the following to a asp.net button onClientClick="return confirm('Are you sure?');"

Hiding an applet before a long treatment postback

I have to integrate a Java applet into a simple asp.net 2.0 control.
This applet is a bought product and cannot be modified. It contains a button designed to be clicked to continue. The button click is linked to a JavaScript function.
So we can see this applet as a black box, eating data and calling a JS function when it's done.
I have to make a postback when the JS function is called to go to the next page. Easy, I just have to write it. But I would also like to hide the applet, or the div containing it, because the postback trigger some long treatment. The point is that, while waiting, the user can click on the applet button and triggers the postback again.
In my JavaScript called function, I tried many solutions:
Make 2 postbacks. Of course this doesn't work, as a postback is a reload of the page
Hide/show the div or the applet using JavaScript
Hide/show the div or the applet using jQuery
Hide/show the div or the applet calling the click event of an invisible button to set Visible = false in the code behind
But it always fails: it seems that the web browser (IE 8.0 or Chrome) waits the end of the postback/JS function to update the page, and don't bother with some UI update just before.
So here I am:
I need the postback to go to the next page (I do not control the entire environment where my control is used)
I have to hide the applet, otherwise the user can re-click on it
I can't make a two-step process, like having the JS function hiding the applet and displaying a link to to the next page, involving a new click
My simple control:
<%# Control Language="C#" AutoEventWireup="false" Codebehind="MyControl.ascx.cs"
Inherits="MyControl" %>
<div id="m_DivPostDisplay" runat="server">
<asp:Label ID="lblState" runat="server" Text="Displaying something like please wait..." />
</div>
<div id="m_DivAppletContainer" runat="server">
<applet name="myApplet" archive="./myJar.jar"
code="Main.class" height="700" width="530" mayscript>
</applet>
</div>
The related javascript (injected when the page load):
<script language='javascript'>
function sendData(data) {
// This is where I try to hide the applet or the div
//.....
// Go to the next page
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(\"nextButtonId\", \"\", true, \"\", \"\", false, true));
}
</script>
Do you have any idea of what could be done to fix my problem?
Thanks :)
Ugly, but you could try :
function sendData(data) {
// hide applet
setTimeout(function () {WebForm_DoPostBackWithOptions(...);}, 500);
}
Finally we asked the applet editor to add a new feature, so we can now disable its buttons when we need.
So when we click on the button, we keep it disabled, launch the postback, and change page when the postback returns.

Categories

Resources