Using the code below, I want to compare the UserType, if it is "Student" I want to redirect to student profile, etc.
But it always gets to the last else statement and Writes an Error.
The returnQuery method works well because it returns the value "Student".
String emailID = Session["New"].ToString();
string usertype = returnQuery(
"select userType from Registration where email = '" + lblEmail.Text + "'");
if (usertype.Contains("Student"))
{
Response.Redirect("Profile.aspx?email=" + emailID.ToString());
}
else if (usertype.Contains("Company"))
{
Response.Redirect("CompanyProfile.aspx?email=" + emailID.ToString());
}
else if(usertype.Contains("Admin"))
{
Response.Redirect("AdminProfile.aspx?email=" + emailID.ToString());
}
else
Response.Write("Error");
If usertype="Student" you can use usertype.Equals("Student"); to determine the variable.
Here is the method.
I suspect that you are dealing with a Page Lifecycle issue. lblEmail.Text is likely not what you expect it to be during Postback Event Handling time of the button click.
Verify that you are not modifying the contents of lblEmail.Text at any point before the button click event is processed, and verify the value of lblEmail.Text at the time the click event is processed.
For more information about Page Lifecycle, see this MSDN article:
https://msdn.microsoft.com/en-us/library/ms178472%28v=vs.100%29.aspx
Related
I am using a WebDialogResult defined on a SmartPanel by calling AskExt() that is used to prompt for a password.
Unfortunately, it caches the password that's entered, so it keeps pre-filling the dialog and I want it to be blank every time the dialog is called.
I've tried a variety of different things, such as calling with .AskExt(true), which is supposed to refresh the dialog and invoked .ClearDialog() before calling .AskExt(), and numerous other things including .Cache.Clear(), .Cache.ClearQueryCache(), .Reset(), .Update(new PwdFields()), .Delete(.Current) as well as the more direct .Current.Pwd = null and .Current.Pwd = "", but nothing works.
That is browser problem. In order to solve it I propose you to find id of control with help of firefox or chrome developer toolbar, and use javascript which will clean values.
Then you can add jquery like this:
$( document ).ready(function() {
$("#ctl00_phG_PXSPanelVerify2_PXFormViewVerify2_CustEdPwd2").focus()
{
$("#ctl00_phG_PXSPanelVerify2_PXFormViewVerify2_CustEdPwd2").text("");
}
});
Eventually the combination below consistently cleared the dialog of the password whenever it was re-displayed.
if (this.PasswordLookup1Status.AskExt(true) == WebDialogResult.OK)
{
string currentPassword = this.PasswordLookup1Filter.Current.Pwd;
this.PasswordLookup1Filter.Current.Pwd = "";
this.PasswordLookup1Filter.Update(this.PasswordLookup1Filter.Current);
if (currentPassword == "1234")
{
Base.Transactions.Ask("Information", "Password [" + currentPassword + "] is correct.", MessageButtons.OK);
Base.Transactions.ClearDialog();
}
else
{
throw new PXException("Password [" + currentPassword + "] is incorrect.");
}
this.PasswordLookup1Filter.ClearDialog();
}
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)
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
I have a code that doing the popup message for the session expired, as following. However, this code cannot do a correct counting session. When run the program, it will direct popup the session expired message which didn't follow the time that I had set. I know that why my message will popup so early because in my
Page.ClientScript.RegisterStartupScript(cstype, csname, strconfirm, false);
I didn't add in the "timeout" so it is not executed as I want, but how to add it? when I try to add it in, it will result as input format error. Can someone assist me for this problem?
string csname = "timeoutWarning";
Type cstype = this.GetType();
if (!Page.ClientScript.IsStartupScriptRegistered(cstype, csname))
{
var timeout = HttpContext.Current.Session.Timeout * 60 * 1000;
string strconfirm = "<script>if(!window.confirm('Your login session is about to expire. Do you want to extend it?')){window.location.href='../login.aspx'}</script>";
Page.ClientScript.RegisterStartupScript(cstype, csname, strconfirm, false);
}
You are no where setting the timeout!
Extract your java script code to function say SessionTimeOutHandler() and call that while sesssion expires:
string strconfirm = "<script>" +
"window.setTimeout('SessionTimeOutHandler()', 60000);" +
"function SessionTimeOutHandler() { "+
" if(!window.confirm('Your login session is about to expire. Do you want to extend it?'))"
+" {window.location.href='../login.aspx'}</script>"; }";
Now, just replace your strconfirm initialization statement. It should work for you!
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.