My JavaScript code is this:
var newwindow;
function poptastic(url) {
newwindow = window.open(url, 'name', 'height=400,width=200');
if (window.focus) { newwindow.focus() }
}
And my C# code:
foreach (GridViewRow row in GvComments.Rows)
{
Button btnReplay = (Button)row.FindControl("btnReplay");
string url = "javascript:poptastic('Configuration.aspx?id=" + e.CommandArgument + "')";
btnReplay.Attributes.Add("onclick", url);
}
I think the C# code has problem, because when I use this JavaScript code in a tag it works, but in attribute.add not working.
Try using OnClientClick for this instead:
btnReplay.OnClientClick = String.Format("poptastic(\"Configuration.aspx?id={0}\");return false;", e.CommandArgument);
EDIT
Here's a JavaScript function you can use to open popup windows:
openChildWindowWithDimensions = function(url, width, height, showMenu, canResize, showScrollbars) {
var childWindow = window.open(url, "", "\"width=" + width + ",height=" + height + ",menubar=" + (showMenu ? "1" : "0") + ",scrollbars=" + (showScrollbars ? "1" : "0") + ",resizable=" + (canResize ? "1" : "0") + "\"");
if (childWindow){
childWindow.resizeTo(width, height);
childWindow.focus();
}
}
This problem would be very easy to answer, if you can provide the HTML generated. To find HTML generated go the browser window where you are seeing the rendered page and do a View Source. See How do I check my site's source code
With the code you have provided all the suggestions I can make are already made by #James Johnson
Please see a minor correction to James code
btnReplay.OnClientClick = String.Format("poptastic('Configuration.aspx?id={0}');return false;", e.CommandArgument);
Note: I have changed \" to '
Related
I'm working on knockout based site using selenium web driver + c# to automate. My test methods fail because of elements not found / not able to click as the site is slow / or the binding/ rendering of html is slow after the ajax calls are finished.
Below is sample code I used to know the ajax calls have finished and I can proceed to search elements.
public static void waitForAjax(IWebDriver driver, String action)
{
try
{
TimeSpan tp = TimeSpan.FromSeconds(1000);
driver.Manage().Timeouts().SetScriptTimeout(tp);
((IJavaScriptExecutor)driver).ExecuteAsyncScript(
"var callback = arguments[arguments.length - 1];" +
"var xhr = new XMLHttpRequest();" +
"xhr.open('GET', '/" + action + "', true);" +
"xhr.onreadystatechange = function() {" +
" if (xhr.readyState == 4 && xhr.status == 200) {" +
" callback(xhr.responseText);" +
" }" +
"};" +
"xhr.send();");
}
catch { }
}
I am calling the above method before going to find the elements.
Test Method
try
{
IWebDriver _Driver;
IWebElement ele;
FirefoxDriverService _Service = FirefoxDriverService.CreateDefaultService(#"D:\CodePlex_C#\SeleniumTestWithHtml\SeleniumTestWithHtml\Drivers");
_Driver = new FirefoxDriver(_Service);
_Driver.Navigate().GoToUrl("HomepageURl");
System.Threading.Thread.Sleep(2000);
waitForAjax(_Driver,"Call1");
waitForAjax(_Driver,"Call2");
System.Threading.Thread.Sleep(2000);
ele = _Driver.FindElement(By.LinkText("DASHBOARD"));
ele.Click();
//System.Threading.Thread.Sleep(2000);
waitForAjax(_Driver,"Call1");
waitForAjax(_Driver,"Call2");
waitForAjax(_Driver,"Call3");
waitForAjax(_Driver,"Call4");
System.Threading.Thread.Sleep(2500);
ele = _Driver.FindElement(By.Id("QuickSearchCnt"));
ele.Click();
}
But my Code Fails. I suspect the code to find the calls have finished to execute is not working properly.
I need help in knowing is my approach right? And need help in fixing the issue.
The title pretty much says it all. A few days ago the FB.Feed was working normally. The user could hit the share button and simply post the pre made feed story to his timeline. Now there has to be some sort of user input involved in order for the story to get posted. Even if its just a white space. Has facebook changed something or what ?
here is the feed method :
if (FB.IsLoggedIn)
{
int shareScore = m_score.globalScore;
string shareMsg1 = "SAmple msg";
string shareMsg2 = "Sample msg2";
if (gameOverFlag)
{
shareScore = m_score.scoreForPost;
shareMsg1 = "game overmsg1";
shareMsg2 = "gameover msg2 ";
}
FB.Feed(
link: "test.com",
linkName: shareMsg1 + (DataHolder.holder.levelIndex + 1).ToString() + " FuBar",
linkDescription: "Some text",
linkCaption: shareMsg2 + shareScore + " and " + score.ToString() + " Stars",
picture: "test.com/test.jpg",
callback: LogCallback
);
}
else
{
FB.Login("public_profile,user_friends,email,publish_actions", LoginCallback);
}
I replaced the proper links with the fictional test.com in the given example.
I'm currently working on a small program that gets data from mongoDB and matches it with other data. My program is currently printing out the data, but it needs to add a <asp:button />with an unique ID to it so I can save the data for each product.
Here is my code:
public void showCoolers_Click(object sender, EventArgs e)
{
var items = "";
var connectionString = "mongodb://localhost:27017/";
var mongoClient = new MongoClient(connectionString);
MongoServer server = mongoClient.GetServer();
MongoDatabase database = server.GetDatabase("mydb");
MongoCollection<cpuCoolers> collection = database.GetCollection<cpuCoolers>("cpucoolers");
foreach (cpuCoolers parts in collection.FindAll())
{
String _id = parts._id.ToString();
items = items + "<tr><td>" + parts.Aanbieder + "</td><td> " + parts.Productnaam + "</td><td>" + parts.Socket + "</td><td> " + parts.Geluidsterkte + "</td><td> " + parts.Prijs +"</td><td><asp:Button ID='x' runat='server' Text='Motherboard' CssClass='btn btn-block btn-primary'/></td></tr>";
}
lblProducts.Text = "<table><thead><tr><th>Provider</th><th>Productname</th><th>Socket</th><th>Sound production</th><th>Price</th><th>Add to MyPc!</th></thead>" + items + "</table>";
}
I print my data via changing the content oflblProduct.Text in my aspx file. If I add a asp:button to this it doesn't show up, however a regular Html button does, why is that and is there a way to print out a asp:button's?
You can't render an asp.net button the way you are trying, you would need to use a regular html button as you found out.
The asp:button is something that asp.net interprets while it is building your page; by the time you _Click function is executed, its too late in the page lifecycle to render asp.net controls - so HTML buttons are your only option at that point in the page execution.
Here is an overview of the asp.net page life cycle that might help you understand it better:
http://msdn.microsoft.com/en-us/library/ms178472%28v=vs.100%29.aspx
Good Day Every one here is my code
if (type.Contains("Loan Date"))
{
prenda.LoanMonth = year.ToString() + "/" + month.ToString();
string a = servs.CheckLM(prenda);
if (Convert.ToInt32 (a) != 0)
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "key", "myFunction();", true);
//create a popup if yes process if no exit
//if yes
prenda.LoanMonth = year.ToString() + "/" + month.ToString();
servs.DeletePrendaLM(prenda);
foreach (DataRow row1 in table.Rows)
{
prenda.Bcode = row1["Bcode"].ToString();
prenda.Jprincipal = Convert.ToDecimal(row1["JPrincipal"].ToString());
prenda.Aprincipal = Convert.ToDecimal(row1["APrincipal"].ToString());
prenda.Cprincipal = Convert.ToDecimal(row1["CPrincipal"].ToString());
prenda.LoanMonth = year.ToString() + "/" + month.ToString();
user.UserID = Session["UserID"].ToString();
servs.UploadPrendaLM(prenda, user);
}
}
the porblem is that the Page.ClientScript.RegisterStartupScript(Page.GetType(), "key", "myFunction();", true); doesnt execute as soon as the process pass over it, it executes myFunction() after finishing the button click proceses, i cant create a if clause below it because it finishes first all of the process before i can use the myFunction() i need that process first before continuing the proceses below //
so can you help me find a work around?
Few things that might help
The script block added by the RegisterStartupScript method executes when the page finishes loading but before the page's OnLoad event is raised. >> Where are you adding script in the page (Which event?) try it in OnInit or init complete events.
You can check whether script added or not through IsStartupScriptRegistered method (Page.ClientScript namespace)
Since yesterday, I try to run a sample of code to display a chart with FusionCharts and Mvc3 Razor and nothing works. Please.... help!!! :)
Here is what I have done:
I took the projet from Libero. here
After that, I used the project convertor here to upgrade the project from Mvc2 to Mvc3.
When I try to run to code (F5 and show the result in browser), that works fine; all graphics are displayed correctly.
If I just create a new view with razor (.cshtml) instead of the current .aspx (replacing a view from the old syntax to the new razor) and I try to displayed the same graphic, the page is displayed correctly but without graphic. When I look into the page source with firebug or any other tools, no code is behind the scene. I also don't have any errors while looking with the Web Developer tool in Firefox.
I just tried to add a Html.Raw in front of the code that generate the javascript to not encode the output and I have the same result. Also trying with returning HtmlString but again same result; no graphic is displayed.
The key to don't miss in this problem is that if I try the exact same code but with an .aspx file, all is correct.
In .aspx, the code looks like this:
<%=Html.FChart("Chart01", ViewData["MyChart"], 600, 400)%>
And in .cshtml:
#{Html.FChart("Chart01", ViewData["MyChart"], 600, 400); }
And finally, the html helper to generate this bunch of code:
private static string RenderChart(string controlId, string xmlData, FusionChartBase chart, int width, int height)
{
String sControlId = controlId;
String sJsVarId = "_lib_JS_" + controlId;
String sDivId = "_lib_DIV_" + controlId;
String sObjId = "_lib_OBJ_" + controlId;
String sWidth = width.ToString();
String sHeight = height.ToString();
StringBuilder oBuilder = new StringBuilder();
oBuilder.AppendLine(#"<div id=""" + sDivId + #""" align=""center""></div>");
oBuilder.AppendLine(#"<script type=""text/javascript"">");
oBuilder.AppendLine(#"var " + sControlId + #" = (function() {");
oBuilder.AppendLine(#" return {");
oBuilder.AppendLine(#" containerId: '" + sDivId + "',");
oBuilder.AppendLine(#" xmlData: '',");
oBuilder.AppendLine(#" chartType: '',");
oBuilder.AppendLine(#" showChart: function() {");
oBuilder.AppendLine();
oBuilder.AppendFormat(#" var chartURL = '{0}' + this.chartType.replace('Chart', '{1}');", UrlSWF, SufixSWF);
oBuilder.AppendLine(#" var " + sJsVarId + #" = new FusionCharts(chartURL, """ + sObjId + #""", """ + sWidth + #""", """ + sHeight + #""");");
oBuilder.AppendLine(#" " + sJsVarId + #".setDataXML(this.xmlData);");
oBuilder.AppendLine(#" " + sJsVarId + #".render(""" + sDivId + #""");");
oBuilder.AppendLine(#" }");
oBuilder.AppendLine(#" }");
oBuilder.AppendLine(#"})();");
oBuilder.AppendLine(#"setTimeout(function(){");
oBuilder.AppendLine(#" " + sControlId + #".xmlData = """ + xmlData.Replace(#"""", #"'") + #""";");
oBuilder.AppendLine(#" " + sControlId + #".chartType = """ + chart.ChartType + #""";");
oBuilder.AppendLine(#" " + sControlId + #".showChart();");
oBuilder.AppendLine(#"},0);");
oBuilder.AppendLine(#"</script>");
return oBuilder.ToString();
}
I don't know if I must set some configuration options in the web.config or what I don't understand in the behavior of Mvc2 compare to Mvc3, but it's very frustrating.
If you have any idea, a big thanx in advance.
It should be #Html.FChart("Chart01", ViewData["MyChart"], 600, 400) instead of #{Html.FChart("Chart01", ViewData["MyChart"], 600, 400); }
FusionCharts provides a .NET library which makes rendering charts a one liner - read through the FusionCharts Documentation.
They have a recent tutorial up on their blog - JavaScript Charts with ASP.NET (C#) Using FusionCharts XT