add "please wait" javascript modal to aspx DetailView insert button - javascript

Using insert functionality of an aspx DetailsView. Would like to show a javascript modal popup window while the new record is processed and added to the database. I can hook the button click in DetailsView_ItemCommand. It's not working, so I started trying to figure out whats going on by simply displaying a javascript Alert() popup. But can't get that to even work. Here's the relevant DetailsView_ItemCommand:
protected void DetailsViewInsertFPL_ItemCommand(object sender, DetailsViewCommandEventArgs e)
{
if (e.CommandName == "Insert")
{
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "waitMessage", "alert('Please wait while your request is processed');", true);
return;
}
}
After the record is inserted, there is a redirect to another aspx page.
Can anyone steer me down the right path? I'll be looking at some of the aspx page and DetailsView properties next to see if something there isn't set correct.

You cant just use
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "waitMessage", "alert('Please wait while your request is processed');", true);
then preceeded by a
response.redirect("toanotherpage.aspx");
ScriptManager.RegisterStartupScript will render your script after all the elements in the page (right before the form's end tag) hence not executing it when you use response redirect on the same code block.
To achieve what you want you could do one of the following solutions,
Create a Javascript and place you the redirect or for this instance
window.location there after the Alert message you want
Create a pop-up modal using other methods like bootstrap, on the modal declare a button with a code for response.redirect.

Alex Kudryashev's suggestion to enclose the DetailView within an asp:UpdatePanel and use the asp:UpdateProgress to show the "please wait while your request is processed" gave me the solution I needed in this case.
Infrequent user here, so not sure how to give the points to Alex as his suggestion was a comment rather than an answer. Feel free to let me know how to handle the votes in that case.
Thanks!!!! I've been banging my head against the wall for a couple of days to get this one working.

Related

How do I get splash to click to click through next page using JS path?

I'm following a tutorial on using Splash to extract data from a table on a javascript website. The code keeps scraping the main page instead of clicking through to the next page, so I end up with 10 repeats of the same page. I've tried changing the button JS path, but same results.
Anyone know how where I'm going wrong?
Here is the URL I'm scraping:
https://eservices.customs.gov.hk/MSOS/wsrh/001s1?searchBy=ALL
Here is the Lua Code from Splash:
function main(splash, args)
assert(splash:go(args.url))
assert(splash:wait(0.5))
treat=require('treat')
result= {}
for i=1,9,1
do
assert(splash:runjs('document.querySelector("#next_grid-table-pubSrch > span").click()'))
result[i]=splash.html()
end
return treat.as_array(result)
end
Turns out I just needed to remove the span tag. Here is the updated script for those who may have similar problem. I hit a 504 error around page around page 99/205, so will have to work that out. Will update when I solve this, no need to reply as you'll need to have my scrapy code for that. This is just for educational viewing now.
function main(splash, args)
assert(splash:go(args.url))
assert(splash:wait(0.3))
treat=require('treat')
result= {}
for i=1,205,1
do
assert(splash:runjs('document.querySelector("#next_grid-table-pubSrch").click()'))
assert(splash:wait(0.3))
result[i]=splash:html()
end
return treat.as_array(result)
end

Html.ActionLink: popup(custom), then redirect

I want to show popup when person clicks on button(which is already done with Html.ActionLink - older code; popup only shows if session variable equals some value...this part is alredy figured out) and is then redirected or new view is returned(this is done in controller).
I have Html.ActionLink(<button name>, <controller>, <action>) and out of that with help of other answers here I made Html.ActionLink(<button name>, <controller>, <action>, null, new { onlick: 'myPopup();'}) where myPopup() is function that creates qjuery modal popup.
But my issue is that sometimes popup doesn't even show or only for few seconds. I think that it's because javascript is async and controller is faster so it returns before javascript code is executed. Does anyone know how to execute javascript code first and then controller code.
I tried to Html.ActionLink(<button name>, <controller>, <action>, null, new { onlick: 'myPopup();return false;'}) as return false should stop default behavior(redirecting to Controller/Action) and then in jquery code I put ajax redirect to controller when button OK in popup is clicked. But problem is I can't seem to make this work, it may be even wrong way?
Any suggestions how to add this function?
Hi and welcome to SO :)
You would need to handle the redirect within your myPopup() function. Assuming you have a "continue" button within your modal. One way you could do it is -
$('#actionLinkId').click(function (e) {
e.preventDefault();
var link = $(this).attr('href');
$('#continue').attr('href', link);
$('#yourModalId').modal();
});

pop up messages once aspx

currently I am facing a problem with pop up msgs.
The messages should prompt out first time click on a NEXT button.
when we go to the next pages and back to the previous pages, and click on the same NEXT button, the pop up msgs should not appear.
how can i fix this?
This is button code
<asp:Button ID="Button1" runat="server" onclick="Button1_Click1" Text="Next" Width="100px" />
This is the function() for my clickedOnce
<script type="text/javascript">
window.document.onload = function()
{
var clickedOnce = false;
Button1.Button1_Click1 = function ()
{
if(!confirm('Please make sure the employee particulars and reporting line details are correct before save. \nClick OK to save and continue if all details are correct.\nClick Cancel and contact HR Admin if details appear is not up to date.'))return false;
clickedOnce = true;
}
}
</script>
Thank you. your kindness and help much appreciated.
Well, since you only want to run it once, could you give the user a cookie that lasts until the browsing session is over when they fist click the button? If they have the cookie, then you could skip over the line of code that you only want to run once.
Your code doesn't work at all. The main issue is how you try to catch click event.
<asp:Button ID="Button1" runat="server" onclick="Button1_Click1" Text="Next" />
It means that Button1_Click1 function runs at server. No client-side event occurs. To do something on client side you have to add onclientclick="someFunction()" to your button declaration.
OK, you add this. Now go to javascript.
function someFunction(){
var clickOnce = getCookie('clickOnce');
//Look #Darkrifts comment (link) how to do it.
//Just in case I reproduce the link http://www.w3schools.com/js/js_cookies.asp
if(!clickOnce || confirm('blah blah')){
document.cookie = 'clickOnce=1';
//no need to return anything
}
//if a visitor doesn't click "ok" then the popup appear again
}
It is also possible to set Session["clickOnce"] = true; on server side and use it from Page_Load server side handler but it may not work if a visitor return to the page using browser Back button.
protected void Button1_Click1(object sender, EventArgs e){
Session["clickOnce"] = true;
//more code
}
protected void Page_Load(object sender, EventArgs e){
if(Session["clickOnce"] != true)
Button1.OnClientClick = "someFunction()";
else
Button1.OnClientClick = "";
//more code
}
This can be achieved in multiple ways. You need to select the most efficient approach for your need. First of all you need to understand the ASP.Net page life cycle, persisting information between pages and ViewState.
In a nutshell...
Whenever your page reloads all elements (including JavaScript variables, be it global or local variables) in your page get's initialised. And then a feature in ASP.Net comes into play. I.e. ViewState. If this is set to true in page level or for each control it'll persist information of the controls in the page (depends on how you set this). But, this is page specific.
And, you could persist information between pages using following approaches
Query string
Session variables
Cache
Form posts
Cookies
Data store (e.g. text, xml or any other database/ data store)
Before you use any of the above mentioned approaches you must think about your requirement. #Alex Kudryashev came up with a good example while I was writing this answer. Let me know if you need example with a different approach or any clarifications.

Alert Message is not showing

I am new in development, I want to show the alert message on button click after that I want to redirect the on another page. my button code is like below:
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
Response.Write("<script type='text/javascript'> alert('Please wait for approval!');</script>");
Response.Redirect("~/profile/scrapbook.aspx?uid=" + Request.QueryString["uid"], false);
}
in this case alert is not working, If I remove the Response.Redirect then it will works properly.
Please suggest me how to call he alert message after that redirect on another page.
You are mixing server side and client side code.
The Response.Redirect("~/profile/scrapbook.aspx?uid= is server side and the Alert won't wait the action of the user to execute it...
What you will need is to do you redirect in Javascript or to use something else than an Alert for the message.
Solution 1
You display a Alert message in Javascript (client side) when the user press okay you do a redirect in Javascript.
Solution 2
You display a message in the HTML with a button in ASP with an event that will do a call to the server and redirect your user to the page you desire.
Add your script like this:
const string scriptString = "<script type='text/javascript'> alert('Your friend request sent to the user! Please wait for approval!');</script>";
ClientScriptManager script = Page.ClientScript;
script.RegisterClientScriptBlock(GetType(), "randomName", scriptString);
Do not use Response.Write to render your JavaScript. Use RegisterClientScriptBlock or RegisterStartupScript instead.
Your example should be using RegisterStartupScript, since it's rendering executing script, and not function declarations.

Refresh parent page after Greybox close

First of all, merry christmas to all of you :)
I have a blog, where people can make comments. I've now decided to put the "writecomments.aspx" file in a Greybox popup-window. It works, but I want to close the window from codebehind (or javascript) after the comment is written. And then I want to refresh the blog page (the parent page) to show the new comment.
This is the code that opens the greybox (writecomments.aspx) page:
Skriv kommentar
In the writecomments.aspx file, I just have 2 textboxes and 1 button (save-button).
How can I make the greybox window close itself, and then somehow refresh the blog.aspx? Or maybe just a specific updatepanel for the current comments?
Edit
I got it working, I had to put this code in the codebehind, after the db-insert: Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "parent.parent.GB_hide();", true);
And for the refresh of the parent page, I edited the gb_scripts.js file on line 12 from false to true: this.reload_on_close=true;
Merry Christmas! :)
EDIT AGAIN
Actually, I modified it a bit, so, I put the gb_scripts.js file back to it's default state, and I just just the followig line of code in the WriteComments.aspx codebehind file, just after the db-insert:
Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "parent.parent.window.location.reload();parent.parent.GB_hide();", true);
Now, the Greybox is closing, and then, the blog page is refreshing, just like I want :)
As I am looking for a similar behavior, this is working in my case:
http://www.phpfreaks.com/forums/index.php?topic=235378.0
"Pleas go through this file (gb_scripts.js)
at line number 12
change 'this.reload_on_close=false;' to 'this.reload_on_close=true'
and line number 67
change 'window.location.reload();' to 'window.location.reload(true);'
and done
« Last Edit: December 20, 2010, 04:38:42 AM by shashidharkumar »"
Once the comment is successfully saved to DB, render the following javascript in the page:
window.opener.reload();
window.close();
In your WriteComments.aspx.cs once the save is successful add the code below to render the javascript in the HTML:
if (!IsClientScriptBlockRegistered("CloseMe"))
{
String cstext1 = "<script type=\"text/javascript\">" +
"window.opener.refresh(); window.close();</" + "script>";
RegisterStartupScript("CloseMe", cstext1 );
}
This is how we do it in JS only.
I got the close function working! This is the code i had to use: Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "parent.parent.GB_hide();", true); Now I'll only have to refresh the parent page some way :)
Here is the well explained ANSWER with easy steps : http://www.codeofaninja.com/2010/12/how-to-refresh-greybox-parent-page.html

Categories

Resources