I am trying to pass parameters to my SSRS report from an .NET application.
I have 3 parameters to pass: instanceID, EL and OL.
In my code-behind, I have codes as below:
string params = Session["instanceID"].ToString() + "&EL=unhide&OL=unhide";
string script = "<SCRIPT LANGUAGE='JavaScript'> ";
script += "OpenLink1(" + params + ");";
script += "</SCRIPT>";
Page.RegisterStartupScript("ClientScript", script);
My javascript code is as below:
function OpenLink1(params ) {
var str = "http://server/ReportServer/Pages/ReportViewer.aspx?%2f<path>%2f<report name>%2<report name>&rs:Command=Render&instanceID=" + params;
window.open(str, "List", "scrollbars=yes,resizable=yes,width=800,height=600");
return false;
}
No matter what I do, the report just won't launch (pop up).
The EL and OL parameters are supposed to hide tables in the SSRS report.
e.g. =IIF(Parameters!EL.Value = "hide", false, true)
If I remove these 2 parameters from the report and take away the parameter in the URL in code behind, the SSRS report launches without any problems.
What confuses me is that if I directly enter the URL in the browser, the report works fine - which lead me to believe that something to do with my coding and passing the parameters is wrong?
Any ideas?!
The issue is in the javascript that you're generating in your code behind. You need to put single quotes around the params variable when you're creating your function call in the generated javascript.
script += "OpenLink1('" + params + "');";
Related
I am having problems trying to save (insert) a .pdf with annotations into a SQL Server database. The database is located inside Visual Studio and I am currently using adobe javascript to save it, but I run into security settings prevent access to this property or method when i clicked the button inside the pdf. I'm using a pdf button field from spire.pdf to try to save into the db and pass the script into pdf javascript action.
So far, i have tried using trusted privilege function, using adbc connection and odbc connection as well as the soap method but it doesn't work and I'm quite lost at what to do or continue next. These methods can be found inside adobe javascript reference as well as api.
PdfPageBase page = pdf.Pages[i];
PdfButtonField button = new PdfButtonField(page, "Save");
button.Bounds = new RectangleF(420, 10, 100, 40);
button.BorderColor = new PdfRGBColor(Color.AliceBlue);
button.BorderStyle = PdfBorderStyle.Solid;
button.ForeColor = new PdfRGBColor(Color.White);
button.Text = "Save";
button.BackColor = new PdfRGBColor(Color.Blue);
button.ToolTip = "Save";
button.Font = new PdfFont(PdfFontFamily.Helvetica, 9f);
pdf.Form.Fields.Add(button);
String script = "var nButton=app.alert({"
+ " cMsg: \"Do you want to save this paper into the database?\","
+ " nIcon: 2,"
+ " nType : 2,"
+ " cTitle: \"Confirm Save?\""
+ "});"
+ "if ( nButton == 4 ) {var myProxy = SOAP.connect(\"http://localhost:57103/test123.svc?wsdl) \"); var testString = (\"This is a test string\"); var result = (myProxy.echoString(testString)); console.println(\"Result is : + result\")};";
PdfJavaScriptAction confirm = new PdfJavaScriptAction(script);
button.Actions.GotFocus = confirm;
The expected result i should get is to be able to save the pdf with annotations into the SQL Server database inside Visual Studio and being able to retrieve it with the annotations. However, the actual result showed the security settings prevent access to this property or method and i cannot proceed to continue.
Would really appreciate some help, thank you! :)
ADBC in Acrobat JavaScript is has been off by default since Acrobat 9. To activate ADBC, create a registry key of type DWORD with the name “bJSEnable” and a value of “true” (1) in the following location:
HKEY_CURRENT_USER\SOFTWARE\Adobe\Adobe Acrobat\VERSION\ADBC
Also the SOAP object was deprecated beginning with Acrobat 8.0. Use Net.SOAP instead.
I want to ask you guys if it is possible to do the following:
Type in textbox something like this "search pluto"
and then it must search for that last word.
This is how I did it but it doens't work because when I do that
my browser opens up twice.
One with "https://www.google.be/#q="
and the other tab that opens is the word that I wrote in
the textbox. Can somebody help me out of this please?
This is the code for this:
string url = "https://www.google.be/#
if (inputTBX.Text.Contains("search ") == true)
{
inputTBX.Text.Replace("search ", "");
string URL = url += inputTBX.Text;
Process.Start(#"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",
URL);
inputTBX.Clear();
}
just as a test in a simple console app I tried the following and it worked launching my default browser
var t = "pluto";
Process.Start("http://google.com/search?q=" + t);
This also works
var t = "pluto";
Process.Start("https://www.google.be/search?q=" + t);
in your case you need to get your query string to be the following
https://www.google.be/#q=pluto
your first problem is that you are trying to use the Replace method but you need to assign it into something here is a working solution of your code just tested notice the differences in what I have done
inputTBX.Test = "search pluto";
string url = "https://www.google.be/search?q=";
if (inputTBX.Contains("search "))
{
inputTBX.Text = inputTBX.Replace("search ", "");
string URL = url += inputTBX;
Process.Start(URL); // this will launch your default web browser
inputTBX.Clear();
}
since your query string has the word search in it.. you really don't need this line if (inputTBX.Contains("search ")) but if you keep it it will work with if you pass search planet pluto for example in your textbox
This part
inputTBX.Text.Replace("search ", "");
Is seriously bad, because it will fail to do its job if you have input string like this
"search research on Beethoven's work"
If you want the key phrase to be "search ", you should do this instead
inputTBX.Text.Substring(("search ").Length); //this way it will skip the "search " phrase and use the rests of the phrase for searching
As for your process with the given URL, simply do
string url = "https://www.google.be/#q="; //notice the q= is missing in your code shown
Process.Start(url + inputTBX.Text.Substring(("search ").Length));
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
I have a web project where clicking a button navigates to another page. The new page can be 1 of three possible pages depending on data in the server. (The url may be the same for 2 of those pages)
I have three classes representing expected elements on each page using the PageObject model.
What is the best way to actually find what page actually got loaded? Is there an OR type of wait that I can wait on three unique elements and get the one that actually got loaded?
Yes, it is possible to check the presence of unique element (which identifies the page) and then return respective page in the framework.
However, a test should know the page it is expecting next and should assume that the correct page has loaded and perform further actions/assertions. You can even put an assertion here to verify correct page has loaded. If a different page has loaded, then the test eventually fails as assertions would fail.
This way test becomes more readable and describes flow of application.
Also, setting up test data upfront for the tests, is always advisable. This way you would know what data is available on server and test would know which page would render.
I had a similar issue where I needed to detect if a login was for a new user (the login page then goes to a terms & conditions page rather than direct to the home page).
Initially I just waited and then tested the second page but this was just a pain so I came up with this.
To Test the result with this:
var whichScreen = waitForEitherElementText(By.CssSelector(HeaderCssUsing), "HOME SCREEN", "home", terms.getHeaderLocator(), terms.headerText, "terms", driver, MAX_STALE_RETRIES);
if(whichScreen.Item1 && whichScreen.Item2 == "terms")
{
terms.aggreeToTerms();
}
The method that this calls is :
protected Tuple<bool, string> waitForEitherElementText(By locator1, string expectedText1, string return1Ident,
By locator2, string expectedText2, string return2Ident, IWebDriver driver, int retries)
{
var retryCount = 0;
string returnText = "";
WebDriverWait explicitWait = new WebDriverWait(driver, TimeSpan.FromSeconds(globalWaitTime));
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(0.5));
while (retryCount < retries)
{
try
{
explicitWait.Until<bool>((d) =>
{
try
{
if (Equals(d.FindElement(locator1).Text, expectedText1)) { returnText = return1Ident; };
}
catch (NoSuchElementException)
{
if (Equals(d.FindElement(locator2).Text, expectedText2)) { returnText = return2Ident; };
}
return (returnText != "");
});
return Tuple.Create(true, returnText);
}
catch (StaleElementReferenceException e)
{
Console.Out.WriteLine(DateTime.UtcNow.ToLocalTime().ToString() +
":>>> -" + locator1.ToString() + " OR " + locator2.ToString() + "- <<< - " +
this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name +
" : " + e.Message);
retryCount++;
}
}
return Tuple.Create(false,"");
}
The explicit wait until uses a boolean so will loop around for the full wait time (I have a very slow Test server so I set this to 60 seconds). the implicit wait is set to half a second so the element tests will attempt every half a second and loop around until either true is returned or it fails.
I use a Tuple so that I can detect which screen I am on, and in this case agree to the terms & conditions which then sets me back on my normal page path
Can somebody look at the below code and tell me what I am doing wrong.
for(i=0;i<=Request.Files.Count;i++)
{
int percentComplete = (int)Math.Ceiling((double)(i + 1) / (double)Request.Files.Count * 100);
string message = string.Format("{0} of {1} uploaded", i + 1, Request.Files.Count);
ScriptManager.RegisterStartupScript(this, this.GetType(), "progress", #"do_progress("+message+","+percentComplete+");", true);
}
I am trying to update the client with each pass of the loop. On the client (inside of the form tags) I have a function called "do_progress" that takes two parameters: message and percent. My intention is that the client-side method fires with each pass of the loop but nothing happens.
UPDATE
Thanks for your help. Ramiz, your code won't work in my case because it collects all the methods (and progress) inside the loop and then sends them to the client at the same time.
This won't show progress accurately (each loop represents the completion of an uploaded file). I need to be accessing the client function, do_progress, after each unique completion of the server-side loop.
Also, the page has already loaded and the code is fired when a (upload) button is clicked.
Having said that, I am still having problems. I can confirm that I am getting the results I want with the below code by looking at 'selection source':
int percentComplete = (int)Math.Ceiling((double)(i + 1) / (double)Request.Files.Count * 100);
string message = string.Format("{0} of {1} uploaded", i + 1, Request.Files.Count);
ScriptManager.RegisterStartupScript(this, this.GetType(), "progress" + i, #"do_progress('" + message + "','" + percentComplete + "');", true);
But, I am not seeing the results update in real-time on the client. The progress bar isn't moving and the counter (n of n files) isn't doing anything. But, when I look at the innerHTML, the values have updated. Very odd. It is almost like I need to be refreshing the page or something but that should't be necessary.
The client side function I am using, which is placed in the form tags at the end of the page, looks like this:
function do_progress(message,percent)
{
try {
$('progress_status').innerHTML = message;
$('progress_bar').attr("style", percent + "px");
}catch(e){alert(e.message)};
}
message is a string value it should be enclosed in single quote "do_progress('"+message+"',"+percentComplete+");"
percentComplete contains integer so it doesn't require to enclose in single quote as message does.
string methods = string.empty;
for(i=0;i<=Request.Files.Count;i++)
{
int percentComplete = (int)Math.Ceiling((double)(i + 1) / (double)Request.Files.Count * 100);
string message = string.Format("{0} of {1} uploaded", i + 1, Request.Files.Count);
methods += "do_progress('"+message+"','"+percentComplete+"');"
}
Secondly, here, I'm incrementing all methods in a string variable and calling it in window.onload event just make sure the DOM is ready before we call the do_progress function.
ScriptManager.RegisterStartupScript(this, this.GetType(), "progress", #"window.onload = function() {"+ methods +"}", true);
However, this should not require here, call in window.onload as ScriptManager.RegisterStartupScript will call them when DOM gets ready.
I'm not sure what exactly issue at your end but this is my instant review.
try to use this.RegisterStartupScript instead of ScriptManager.RegisterStartupScript
Your client side do_progress function appears to have an error in the jQuery selectors - you're currently looking for elements named progress_status and progress_bar when I suspect you intend to be looking for classes or IDs. If your selector doesn't match anything it doesn't raise any kind of error, it just doesn't do anything.