In my application I'm showing a javascript pop up with a web page in it with the help of the following code:
popwin = window.open(URL, '" + id + "',
'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=750,
height=600,left = 262,top = 84');
which is giving me the required pop up with the web page in it.
I want to know whether there is any way to remove user interaction from this pop up and to remove the close button as well.
I will close this pop up using some timer ,but i don't want that user to be able to control the pop up. Is there any way for it?
I googled a bit but haven't got the relevant way to do it.
Note: Can i do this using Modal Pop Up?
Please suggest any good ways .
You can try following code.
popwin = window.open(URL, '" + id + "','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=750, height=600,left = 262,top = 84');
SetTimeOut(function(){ popwin.close()},2000);
Here '2000' is time in milliseconds. 2000 ms = 2sec.
Let me know if any error occurs.
You can try Telerik Radwindows.
You can load your content in a Fancy Box and customize the fancybox as per your needs.
I think it could be more appropriate to use a CSS-like popup instead.
Working example:
http://www.pat-burt.com/csspopup.html#
As for your timer you could change the css attribute with your timer or use some jquery framework plugin like impromptu:
http://trentrichardson.com/Impromptu/
Which cost less time to deploy than the css solution I think.
hey man this is my popup. its not a window but acts like a window and is in jquery and javascript both.
$("document").ready( function() {
var link = ""; // your link here
var d = document.createElement("div");
d.style.display = "block";
d.style.border = "1px solid #282828";
d.style.background = "#ffffff";
d.style.width = "750px";
d.style.height = "450px";
d.setAttribute("id", "popup");
var m = document.createElement("iframe");
m.setAttribute("src", link);
m.style.width = "750px";
m.style.height = "450px";
m.style.border = "0";
document.body.appendChild(d);
d.appendChild(m);
var s=0;
var n = setInterval( function() { s=s+1; if (s == 5) {
$("#popup").remove();
} }, 1000);
});
http://jsfiddle.net/APKTX/
Related
I'm trying to add a page number to the bottom of the page, which doesn't seem to work as expected.
Currently i'm using this:
<span class="page"></span>/<span class="topage"></span>
The problem with this solution is that it doesn't count the cover as a page.
So a 7 page PDF "has" 6 pages according to my code.
I'm looking for a way to include the Cover as a page, so the number is correct.
Currently i'm looking into some JS to manipulate it afterwards, but there have to me some "official" solution?
Solved using javascript. :)
If anyone are looking for the solution here you go:
var x=window.location.search.substring(1).split('&');
for (var i in x) {
var z=x[i].split('=',2);
vars[z[0]] = unescape(z[1]);
}
var pageNumberStart = parseInt(vars.page);
var pageNumberEnd = parseInt(vars.topage);
if (pageNumberStart != null && pageNumberEnd != null) {
document.getElementById('page').innerHTML = pageNumberStart + 1;
document.getElementById('topage').innerHTML = pageNumberEnd + 1;
}
Maybe someone got the official way to do it? :D
I have a text field that contains a 2 digit value by default. I want to clear it before I type a new value. I was using TextSlider.Clear(); but after the latest ChromeDriver update, it's no longer working so I am trying to workaround it using backspace. Currently I am doing two backspaces, one at a time.
TextSlider.SendKeys(Keys.Backspace);
TextSlider.SendKeys(Keys.Backspace);
I also tried DELETE but that's also not working. Is there any way to do this in a single line?
Thank you all,
i have managed to workaround using ctrl A and Delete
TextSlider.SendKeys(Keys.Control + "a");
TextSlider.SendKeys(Keys.Delete);
TextSlider.SendKeys(Keys.Backspace + Keys.Backspace);
First try to fix like how TextSlider.Clear(); is not working. There might me loading issue, SendKeys method will work. Try to add wait for page to load properly.
If still not working then you can use,
TextSlider.Click();
TextSlider.Clear();
But below functionality will definatly work,
TextSlider.SendKeys(Keys.Backspace + Keys.Backspace);
Instead of using Keys.Backspace, ideally to clear a text field you need to induce WebDriverWait for the element to be clickable and you can use either of the following solutions:
Using ElementToBeClickable Method (IWebElement):
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(TextSlider)).Clear();
Using ElementToBeClickable Method (By):
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(By.CssSelector("css_TextSlider")).Clear();
Another option is to clear the text element by using Javascript. Due to issues occurring in certain parallel testing situations, I stopped relying on the SendKeys function some time ago. Instead, I use these functions now to set a certain text:
private void SetText(IWebElement element, string text, bool clearOldText)
{
// Clear old text if needed
if (clearOldText)
{
LogInfo("Clearing " + element.ToString() + #" from any text.");
SetElementValue(element, "");
}
element.Click();
SetElementValue(element, text);
}
public string SetElementValue(IWebElement element, string value)
{
ScrollToElement(element);
PaintElement(element, "yellow");
var exec = (IJavaScriptExecutor)this;
var script = #"
var el = arguments[0];
el.value = '" + value + #"';
try
{
if (""createEvent"" in document) {
var evt = document.createEvent(""HTMLEvents"");
evt.initEvent(""change"", false, true);
el.dispatchEvent(evt);
}
else
el.fireEvent(""onchange"");
}
catch(err){ return err; }
return ""Javascript executed."";
";
LogInfo("Setting value to '" + value + "' for " + element.ToString());
var result = exec.ExecuteScript(script, element);
Recorder?.AddScreenshot();
return result.ToString();
}
Personally I dislike the hardcoded javascript a bit, but it always did the job reliably. "SetElementValue" is called twice in this code to ensure correct handling of certain events in my tests: it might not be necessary in other cases.
I am developing an application in which their exist a problem. When i click on to submit button, the data is inserted into db. But when i press ctrl+R or f5 a chrome or IE pop up occurs which says Confirm Form Resubmission. when i click continue then the record is duplicated into database.
My question is,
Why is this popup occuring? because of the postback? if because of postback then do my code have any issues or it occurs with every body when doing postback.
Will using mvc will solve this issue completely?
My code:
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
paramArray = new string[9];
paramValues = new object[9];
try
{
paramArray[0] = "#AccountNumber";
paramValues[0] = (!string.IsNullOrEmpty(this.txtAccountNumber.Value) ? this.txtAccountNumber.Value.Trim() : string.Empty);
paramArray[1] = "#OpeningBalance";
paramValues[1] = (!string.IsNullOrEmpty(this.txtOpeningBalance.Value) ? Convert.ToDouble(this.txtOpeningBalance.Value.Trim()) : 0.00);
paramArray[2] = "#ClosingBalance";
paramValues[2] = (!string.IsNullOrEmpty(this.txtClosingBalance.Value) ? Convert.ToDouble(this.txtClosingBalance.Value.Trim()) : 0.00);
paramArray[3] = "#PaymentMode";
paramValues[3] = this.ddlModeofPayment.Value;
paramArray[4] = "#PaymentDate";
paramValues[4] = this.dtPaymentDate.Value;
paramArray[5] = "#PaymentAmount";
paramValues[5] = (!string.IsNullOrEmpty(this.txtPaymentAmount.Value) ? Convert.ToDouble(this.txtPaymentAmount.Value.Trim()) : 0.00);
paramArray[6] = "#isAccount";
paramValues[6] = true;
paramArray[7] = "#UserId";
paramValues[7] = (!string.IsNullOrEmpty(this.User.Identity.Name.Remove(0, 7)) ? this.User.Identity.Name.Remove(0, 7) : string.Empty);
paramArray[8] = "#isProcessed";
paramValues[8] = default(bool);
var success = herlperUtility.ExecuteParameterizedQuery("{CALL asp_sp_InsertPayment(?,?,?,?,?,?,?,?,?)}", paramArray, paramValues);
if (!string.IsNullOrEmpty(success.Rows[0]["ReferenceNumber"].ToString()))
{
this.Page.Response.Redirect("AccountPaymentScreen.aspx?flag=1");
divSuccess.Attributes.Add("style", "display:block");
this.refId.InnerText = "<b>Success!</b> The " + success.Rows[0]["ReferenceNumber"] + " has been successfuly forwarded to the supervisor";
this.ClearFields();
}
else
{
this.divFailure.Attributes.Add("style", "display:block");
}
}
catch (Exception ex)
{
this.divFailure.Attributes.Add("style", "display:block");
this.divFailure.InnerText = ex.Message;
}
}
The solution to this is to follow the Post-Redirect-Get pattern. This means that after an HTTP POST in which you do some kind of transactional activity you redirect the client to an HTTP GET.
In a very simplistic way of thinking: GET should not modify anything, while POST is there to make changes.
For example, consider the following workflow.
The user presses submit on an shopping cart page (HTTP POST).
You validate that a credit card is valid and if so charge the
account and set your warehouse activities in motion
You show a screen confirming the order.
If everything goes well and you haven't redirected the client (e.g., you show a panel with a success message and hide the cart) and the client presses refresh, the order will be resubmitted which is probably not ideal for anyone other than accounts receivable.
Following the PRG pattern, after submitting the order you would redirect to a GET page (possibly with the order id in the query string so you have some way of referencing the order) and show your success message. This page can be refreshed as many times as the customer wants (with the added bonus of being bookmarkable) with no side-effects to your back end system or the customer's wallet.
It's worth noting that you don't have to be fanatical about this. In this example if the credit card validation failed you could choose to just display the results of the POST action and toggle an error message on your page. If the user refreshes the page, the validation will run and fail again but no changes will be made to your back end system.
As for MVC - It's not so much that it's easier to accomplish this (it is), it's that you end up thinking about these kinds of things a little more than when using WebForms which (for better or worse) hides these concepts behind an abstraction.
Here's the deal. Have a functioning web app using ASP.NET WebForms with a C# backend. The thing works fine, but I'm always looking to improve, as a beginner at this stuff. Right now, to deal with a user's search coming back with no results, I utilize the following, and was wondering if there was any cleaner way to do it, for future reference:
DataClass data = new DataClass();
var searchresults = data.GetData(searchBox.Text);
int datanumber = searchresults.Count();
if (datanumber == 0)
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", "javascript:alert('There were no records found to match your search');", true);
}
else
{
DropDownList1.Visible = true;
DropDownList1.Items.Clear();
DropDownList1.DataSource = searchresults;
DropDownList1.DataBind();
}
I agree with the not using popups, so you could always do something as simple as having a Label object on your page:
<asp:Label runat="server" id="lblResultMsg" ForeColor="Red" Visible="False" />
And then set the text dynamically (or add it as a property to the code) and set the label to be visible on postback if no results are found:
if (datanumber == 0)
{
lblResultMsg.Text = "There were no records found to match your search.";
lblResultMsg.Visible = true;
}
else
{
lblResultMsg.Text = "";
lblResultMsg.Visible = false;
// do your data binding
}
But there are quite a vast number of ways you could achieve something like this. Regarding your question about using the .Count from the Enumerable collection - there's nothing stopping you doing this as it's perfectly valid. The question is which method do you find more readable?
if you include the jquery ui dialog (http://jqueryui.com/demos/dialog/), you can simply call this to create a nice dialog box:
$('<div>message</div>').dialog({autoOpen:true,title:'Error'});
Personally I prefer to create a helper function for inserting the relevant javascript into the page, and only pass parameters to the function so that I don't need to worry about the messy details every time.
Something like :
public static void GrowlMessage(System.Web.UI.Control pageControl, string header = "", string message = "", bool sticky = false, string position = "top-right", string theme = "", bool closer = true, int life = 8)
{
string _js = "$.jGrowl('" + HttpContext.Current.Server.HtmlEncode(message) + "', { header:'" + header + "', sticky:" + sticky.ToString().ToLower() + ", position: '" + position + "', theme: '" + theme + "', closer: " + closer.ToString().ToLower() + ", life:" + life * 1000 + "});";
ScriptManager.RegisterStartupScript(pageControl, pageControl.GetType(),"Growl",_js, true);
}
The sample I have used also requires jQuery and the jGrowl library available here. And IMHO the messages are pretty. They are unobtrusive, the user does not need to click a button to make them go away, and they fade away after your specified amount of time.
But I agree with Mike, that if you don't have any records, you should just use the built in properties of a GridView (EmptyDataRowStyle and EmptyDataRowText) to display a 'no data matching your query' style message. Assuming that you're using a GridView at all, that is..
When it comes to user feedback, Impromptu is my friend. There is a nice ASP.NET implementation of Impromptu on Aaron Goldenthal's website: http://www.aarongoldenthal.com/post/2009/11/11/Using-jQuery-Impromptu-With-ASPNET.aspx
If you have decided to alert user via alert then please go ahead with light box effect..
http://www.designyourway.net/blog/resources/30-efficient-jquery-lightbox-plugins/
if you are still would like to go ahead with traditional alert then obviously its easy for you to fire it up on page load rather than attaching script to it..
')" ....>
Because if you require any change then you just need to alter the javascript alone and you dont need to build project again to test it...
Hope its useful for you..
Note: I'm using my own DLLs to render content so above coding may requires alteration because i did forget traditional asp codings.. :)
I have application like where i can create dynamic tabs. and delete cross bar option on tabs. When I am trying to delete the tab I am getting error like
Microsoft JScript runtime error: 'null' is null or not an object and point to my Javascript code.
Here is my JS code.
<script type="text/javascript">
/* <![CDATA[ */
function deleteTab(tabText)
{
var tabStrip = $find("<%= RadTabStrip1.ClientID %>");
var multiPage = $find("<%= RadMultiPage1.ClientID %>");
var tab = tabStrip.findTabByText(tabText);
var pageView = tab.get_pageView();
var tabToSelect = tab.get_nextTab();
if (!tabToSelect)
tabToSelect = tab.get_previousTab();
tabStrip.get_tabs().remove(tab);
multiPage.get_pageViews().remove(pageView);
if (tabToSelect)
tabToSelect.set_selected(true);
}
/* ]]> */
</script>
and in page lode
if (!Page.IsPostBack)
{
RadTab tab = new RadTab();
tab.Text = string.Format("New Page {0}", 1);
RadTabStrip1.Tabs.Add(tab);
RadPageView pageView = new RadPageView();
pageView.Height = new Unit("50px");
pageView.Width = new Unit("1300px");
RadMultiPage1.PageViews.Add(pageView);
BuildPageViewContents(pageView, RadTabStrip1.Tabs.Count);
RadTabStrip1.SelectedIndex = 0;
}
This error can occur if you are trying to use an object which is null. In that code quite a lot of things can return null: $find, findTabByText, getPageView, get_nextTab, get_previousTab etc. I suggest you alert() everything before using it. That way you will find what is null.
You're not checking any of those function calls to see if they're actually returning something. One of them is returning null, but your code does not notice that and tries to use the result in a subsequent statement.
Try this in Firefox with Firebug and you'll probably get better error messages.
$find can return null if you are trying to call it too early. Remember that ASP.NET AJAX controls are created during the Sys.Application.Init event. If you try to access them earlier (e.g. in the window.onload) the $find() will not work.