RequiredFieldValidator ErrorMessage does not delete itself even though TEXT does? - c#

This is some old code that I am not too familiar with :
RequiredFieldValidator vldRequired = new RequiredFieldValidator();
vldRequired.Display = ValidatorDisplay.Dynamic;
vldRequired.Text = "*";
vldRequired.ControlToValidate = "txtSetting";
vldRequired.ID = "vldRequired";
vldRequired.Enabled = true;
vldRequired.ErrorMessage = SettingTitle + " is required";
returnCell.Controls.Add(vldRequired);
Where, IF you tab passed a required field the * will show up next to it. THE ErrorMessage only shows up when a Submit is clicked (that is all fine).
However, once you fill in the required field and tab out of the input, the "*" goes away but the ErrorMessage stays -- I cannot figure out how to make that ErrorMessage go away when the * does.
Help?

Ok, I just ran into a similar issue on one of my projects. It's been a while since I've used the requiredFieldValidator. Try removing your Text Property as it interferes with the Error Message. Also ensure that you don't have a Validation Summary on the page as that may cause fixed messages to linger in front of the user even though they have corrected the the problem on the client side.
RequiredFieldValidator vldRequired = new RequiredFieldValidator();
vldRequired.Display = ValidatorDisplay.Dynamic;
//vldRequired.Text = "*";
vldRequired.ControlToValidate = "txtSetting";
vldRequired.ID = "vldRequired";
vldRequired.Enabled = true;
vldRequired.ErrorMessage = SettingTitle + " is required";
returnCell.Controls.Add(vldRequired);

Related

DocuSign SOAP API Title Tab does not keep value

I am using DocuSign SOAP API in an ASP.NET app in C# to send some docs for e-signature.
One of the field is the title tab. I have the following code for that.
When testing, the tab correctly shows the title, which is picked up from the back-end DB. But when I see the completed document, the title is changed to something else. Does anyone know how can I resolve this?
When signing, if I modify the value - add and remove space - it works OK.
tab5 = new DocuSignAPI.Tab();
tab5.RecipientID = rcpt1.ID;
tab5.DocumentID = docId;
tab5.Type = DocuSignAPI.TabTypeCode.Custom;
tab5.CustomTabType = DocuSignAPI.CustomTabType.Text;
tab5.Name = "clientTitle";
tab5.CustomTabTypeSpecified = true;
tab5.Value = (dr["Rcpt_1_Role"]).ToString();
tab5.Type = DocuSignAPI.TabTypeCode.Title;
tab5.AnchorTabItem = new DocuSignAPI.AnchorTab();
tab5.AnchorTabItem.AnchorTabString = "CLIENT TITLE:";
tab5.AnchorTabItem.Unit = DocuSignAPI.UnitTypeCode.Pixels;
tab5.AnchorTabItem.UnitSpecified = false;
tab5.AnchorTabItem.IgnoreIfNotPresent = true;
tab5.AnchorTabItem.UnitSpecified = true;
tab5.AnchorTabItem.YOffset = -10;
tab5.AnchorTabItem.XOffset = 100;
When using certain DocuSign tab types (such as titleTabs or emailTabs for instance) the DocuSign platform will populate some of that information from the user's account if they have one.
For example, if the user has a DocuSign account where they have entered the title "CEO", then whenever you send an envelope to that exact recipient (name and email combo) and you use a titleTab the system will populate from their account.
I do not believe there is a way to override this, probably your best option is to just use a textTab instead and with that you can populate with any data from a database or wherever else you want to supply it from.

TFS WorkItem Validation error

So here's the case: I am trying to create a Task WorkItem. I have to get the data from a dataGridView, which I think I managed to. But the fun part comes when I try to save, or validate the WorkItem. No matter what value State has, the validator always comes with InvalidListValue on execution of wiTask.Validate();. I have tried even hard-coding the State's value, but nothing happens. There is one thing that bothers me a bit - in the Validation array the error comes within the Status property, where the actual control has only State available. Here are some code and a snippet of the error bit:
WorkItem wiTask = new WorkItem(workItemType)
{
Title = form1.dg_taskView.Rows[rows].Cells["titleDataGridViewTextBoxColumn"].Value.ToString() + " " + form1.tb_details.Text,
Description = form1.dg_taskView.Rows[rows].Cells["descriptionDataGridViewTextBoxColumn"].Value.ToString(),
AreaId = int.Parse(form1.dg_taskView.Rows[rows].Cells["areaIDDataGridViewTextBoxColumn"].Value.ToString()),
AreaPath = form1.dg_taskView.Rows[rows].Cells["areaPathDataGridViewTextBoxColumn"].Value.ToString(),
IterationId = int.Parse(form1.dg_taskView.Rows[rows].Cells["iterationIDDataGridViewTextBoxColumn"].Value.ToString()),
IterationPath = form1.dg_taskView.Rows[rows].Cells["iterationPathDataGridViewTextBoxColumn"].Value.ToString(),
State = form1.dg_taskView.Rows[rows].Cells["stateDataGridViewTextBoxColumn"].Value.ToString()
};
ArrayList result = wiTask.Validate();
wiTask.Save();
var hierarchicalLink = _workItemStore.WorkItemLinkTypes["System.LinkTypes.Hierarchy"];
userStory.WorkItemLinks.Add(new WorkItemLink(hierarchicalLink.ForwardEnd, wiTask.Id));
userStory.Save();
As it turns - the validation returns to the array the column that has issues. After further examination the issue is resolved by specifying to Assigned to name, which is part of the project contributors' list.

Adding forward text to email

I'm having a slight problem with adding text to forwarding emails. This is my current code:
private void ForwardFunction(Outlook.MailItem email)
{
Outlook.MailItem forwardEmail = ((Outlook._MailItem)email).Forward();
Outlook.Inspector forwardInsp = forwardEmail.GetInspector;
Word.Document forwardDoc = forwardInsp.WordEditor;
Word.Range forwardRange = forwardDoc.Range(0,1);
string forwardText = "This is some text";
forwardRange.Text = forwardText + forwardRange.text
newEmail.Recipients.Add("myemail");
forwardEmail.Save();
((Outlook._MailItem)forwardEmail).Send();
}
I've gone through it and it does add the text to the range, but when I receive the forwarded email it doesn't contain any of the additional text. I've used similar code to edit current emails that the user is editing (New, Replies/Forwards, InlineResponses) with success, but the email being passed to the function is the currently selected email in the inbox. Not sure if this matters, maybe because it's not being edited by the user.
I couldn't find a specific way to add new text to a programmatically forwarded email.
For anyone else interested in this, I ended up using the .HTMLBody. It seems that using the .GetInspector either gets the inspector of the _email instead of fEmail and you can't edit it or it gets the correct inspector but it can't edit it. Either way, using the .HTMLBody seems to get around it.
Outlook.MailItem fEmail = ((Outlook._MailItem)_email).Forward();
string forwardText;
forwardText = "class=MsoNormal>";
forwardText += "This is my forwarded message";
forwardText += "Bonus hyper link <a href='" + hyperlinkText + "'>" + hyperlinkText + "</a>";
var regex = new Regex(Regex.Escape("class=MsoNormal>"));
fEmail.HTMLBody = regex.Replace(fEmail.HTMLBody, forwardText, 1);
fEmail.Save();
fEmail.AutoForwarded = true;
((Outlook._MailItem)fEmail).Send();

Why is this alertbox not appearing?

I've got almost got a web project finished for an assignment, but I've hit a stumbling block in the form of an alertbox that refuses to pop up when called. The assignment is to create a web form for users to submit personal information to a website. Once they fill in all the textboxes and click a button to register, that will call the function registerMe in the code behind as seen below. Once they do that, the idea is that the function will first check to make sure that the user hasn't already registered on the website, then it will stuff all the values from the Textboxes into a Session object (which is using Candidate.curCandidate as a wrapper). This Session object will then be added to the Application state data to save it.
Now, here's the weird thing. In the if statement below, if the statement is true, all the values will be saved to the session and then the Application state data as desired, but the Alertbox won't appear. However, if the if statement is false, an Alertbox WILL appear. So, I'm guessing that somehow reading and writing all these values is interfering with the activation of an Alertbox, but I have no idea why.
protected void registerMe(object sender, EventArgs e)
{
String successText;
if (Candidate.curCandidate.appProperty == false)
{
Candidate.curCandidate.ssNumberProperty = socSec.Text;
Candidate.curCandidate.emailAddressProperty = email.Text;
Candidate.curCandidate.userIDProperty = userName0.Text;
Candidate.curCandidate.passwordProperty = password0.Text;
Candidate.curCandidate.dateOfBirthProperty = dateBirth.Text;
Candidate.curCandidate.firstNameProperty = fName0.Text;
Candidate.curCandidate.lastNameProperty = lName0.Text;
Candidate.curCandidate.streetAddressProperty = strAdd0.Text;
Candidate.curCandidate.cityProperty = city0.Text;
Candidate.curCandidate.stateProperty = state0.Text;
Candidate.curCandidate.positionProperty = jobs0.SelectedIndex;
Candidate.curCandidate.applicationStatusProperty = appStatus0.Text;
Candidate.curCandidate.appProperty = true;
Application[Candidate.curCandidate.ssNumberProperty]=Candidate.curCandidate;
successText = "Thank you. Candidate Information Added Successfully.\n" +
"E-Mail Address You Entered will be used to notify you of any\n" +
"updates for the position you applied for.";
ClientScript.RegisterStartupScript(this.GetType(), "myalert",
"alert('" + successText + "');", true);
}
else
{
successText = "Registration unsuccessful.";
ClientScript.RegisterStartupScript(this.GetType(), "myalert",
"alert('" + successText + "');", true);
}
}
Try to remove \n from successText and see if it works.
If you really need it, try to double escape it like below:
successText = "... Successfully.\\n"

Debugging: Microsoft JScript runtime error

I am desperately in need of debugging help, been stuck at this error for 6 days now.....
the error I get in my ASp.net app is :
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near '<script type='text/j'.
Below is the relevant code snippet,
CollyDataExchangeWebService Col_ValSub = new CollyDataExchangeWebService();
CollyReportServiceRequest ServiceReq = new CollyReportServiceRequest();
CollyReportServiceRequestData ServiceReqData = new CollyReportServiceRequestData();
ServiceReqData.AmendmentIndicatorSpecified = true;
ServiceReqData.AmendmentIndicator = false;
ServiceReqData.CollyReport = ColRep;
ServiceReq.ServiceRequestData = ServiceReqData;
ServiceReq.ServiceRequestHeader = ServiceHeader;
errValidate = null;
//btnOK.OnClientClick = "MSGShow()";
bool Valid = true;
string ErrMsgs = "";
if (((System.Web.UI.WebControls.Button)(sender)).CommandArgument == "Validate")
{
CollyReportServiceResponse ValResponse = Col_ValSub.validateReport(ServiceReq);
switch (ValResponse.ServiceResponseHeader.ServiceStatus)
{
case ServiceStatus.Successful:
btnOK.OnClientClick = "";
valHeader.Text = "Validation is Completed. No errors were found";
mlValPopup.Show();
break;
case ServiceStatus.ValidationErrors:
Valid = false;
ErrMsgs = ErrMsgs + _ValidationError(ValResponse);
ValBTN.Update();
mlValPopup.Show();
break;
case ServiceStatus.SystemError:
btnOK.OnClientClick = "";
Valid = false;
ErrMsgs = ErrMsgs + _SystemError(ValResponse);
ValBTN.Update();
mlValPopup.Show();
break;
}
After hours of debugging I found this line to be causing the error:
CollyReportServiceResponse ValResponse = Col_ValSub.validateReport(ServiceReq);
After 6 days of debugging and frustration I found that SOME records cause this issue and others dont in OLDER versions of the code but in new version ALL of the records lead to this error so it has to do something with the data in the DB which means SOME method in the code behaves differently to nulls but I cant find out exactly what the issue is because my app is 30k lines of code
after searching around and trying various solutions, the below 2 are not the solutions to my issue.
forums.asp.net/t/1357862.aspx
http://www.vbforums.com/showthread.php?t=656246
I want to mention that I am already having a difficult time dealing with this application because it was written by other programmers that are now long gone leaving behind non-documented or commented spaghetti code.
I did not code this but other programmers from past have put Response.Write in code:
private void MessageBox(string msg)
{
if (!string.IsNullOrEmpty(msg))
{
Global.tmpmsg = msg;
msg = null;
}
Response.Write("<script type=\"text/javascript\" language=\"javascript\">");
Response.Write("window.open('ErrorPage.aspx?msg=" + "','PopUp','screenX=0,screenY=0,width=700,height=340,resizable=1,status=no,scrollbars=yes,toolbars=no');");
Response.Write("</script>");
}
This one is in another method:
Response.Write("<script type=\"text/javascript\" language=\"javascript\">");
Response.Write("alert('No search resuls were found');");
Response.Write("</script>");
Or This:
if (!string.IsNullOrEmpty(msg))
{
Global.tmpmsg = msg;
Response.Write("<script type=\"text/javascript\" language=\"javascript\">");
Response.Write("window.open('ErrorPage.aspx?msg=" + "','PopUp','screenX=0,screenY=0,width=700,height=340,resizable=1,status=no,scrollbars=yes,toolbars=no');");
Response.Write("</script>");
}
After Jrummel`s comment I added this to code and then nothing at all happened.
private void MessageBox(string msg)
{/*
if (!string.IsNullOrEmpty(msg))
{
Global.tmpmsg = msg;
msg = null;
}
Response.Write("<script type=\"text/javascript\" language=\"javascript\">");
Response.Write("window.open('ErrorPage.aspx?msg=" + "','PopUp','screenX=0,screenY=0,width=700,height=340,resizable=1,status=no,scrollbars=yes,toolbars=no');");
Response.Write("</script>");
*/
// Define the name and type of the client scripts on the page.
String csname1 = "PopupScript";
Type cstype = this.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname1))
{
String cstext1 = "<script type=\"text/javascript\" language=\"javascript\">" + " " + "window.open('ErrorPage.aspx?msg=" + "','PopUp','screenX=0,screenY=0,width=700,height=340,resizable=1,status=no,scrollbars=yes,toolbars=no');" + " " + "</script>";
cs.RegisterStartupScript(cstype, csname1, cstext1, false);
}
}
I have found the error after 2 weeks of debugging and 2 days of Brute Forcing:
In one of the 800 DB columns that I have there was a null/improper value. This value reacted with one of the 150 methods in my ASP.NET code in such a way as to present a JavaScript error even though Response.Write() was NOT the issue. I have not found which method it was that reacted to this value but I have found the solution which is to simply input a valid value on the column record..
How a programmer can brute force to find the issue:
In my case after long days of debugging I took a sample of one working record and another sample of an error leading record. Once I had achieved this, I used
DELETE FROM tablename WHERE UniqueColID= unique identifier for the error causing record
Then I did:
INSERT INTO tablename ([uniqueIdentifier],[ column 2],[column 3]) SELECT #UniqueIdentifierofErrorCausingRecord, column2, [column3] FROM TableName WHERE [uniqueIdentifier]=#UniqueIdentifierForWorkingRecord;
What the first statement does is delete the non working record then the 2nd statement reinserts that record with identical column values of the working record but with the UniqueIdentifier of the Non working record. This way I can go through each table to find which table is causing the error and then I can pinpoint which column of that table is the issue.
The specific issue in my case was DateTime.TryParse() because a table column value was inserted in improper format.. The code performed field population in one of the methods without a try and catch using the DateTime.Parse method.... After some testing it seems even a try/catch is not able to pick this error up as it is a javascript error..
Don't use Response.Write().
Instead, create a LiteralControl and add it to the page.
Use ClientScriptManager to add scripts to the page. Here's an example from MSDN:
// Define the name and type of the client scripts on the page.
String csname1 = "PopupScript";
Type cstype = this.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname1))
{
String cstext1 = "alert('Hello World');";
cs.RegisterStartupScript(cstype, csname1, cstext1, true);
}

Categories