How to store placeholder value in xamarin.forms entry - c#

I would like it so my users do not have to type in wifi credentials everytime they are filling out this form on my xamarin.forms app. I'm trying to figure a way where I can store the value that the user last inputted into an entry. Any suggestions?
I thought it could be as easy as storing it to a field if not null but i get an error stating "Only assignment, call, increment, decrement, await, and new obect expresions can be used as a statement"
At the top of my class I have field.
string WifiNamePlaceholder;
Then later in the page I have my entry
if (WifiNamePlaceholder == null)
{
WifiNamePlaceholder = "Enter in your wifi credentials"
}
wifi_name = new Xamarin.Forms.Entry
{
BackgroundColor = Color.White,
Placeholder = WifiNamePlaceholder,
Margin = new Thickness(0, 0, 10, 0),
FontFamily = Fonts.HelveticaNeueBold,
FontSize = labelSize
}
//Attempt to set new value here but get error
//Doing this in hopes it can save their entry for next time.
wifi_name.Placeholder == WifiNamePlaceholder;
If you have any suggestions it would be greatly appreciated! Thank you!

Use Xamarin.Essentials.Preferences or Xamarin.Essentials.SecureStorage. They're easy to use and don't require a bunch of overhead.
Xamarin.Essentials.Preferences.Get("Key", default(string));
Xamarin.Essentials.Preferences.Set("Key", "stringToSave")
Then just set your Entry.Text using the stored value.
See documentation: Xamarin.Essentials.Preferences

Entry.Placeholder is actually only useful for empty Entry's. It's just an informational text that is shown when Entry.Text is empty. So once the user has entered a value you would set Entry.Text the next time the page is shown.
You should really take some time to familiarize yourself with the way data binding works in Xamarin.Forms and MVVM in general.

You could save it in a local database on the user's phone and then fill the placeholder with the value you get from the database
try this link:
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/data/databases

Try saving it in the database or in an xml file.
This way you can use it in your whole application.

if you are using api calls then try to save that password in the backend , so that you can fetch the password by calling that api whenever user open the app.
Otherwise just save the password in shared prefernces so that it ll remain save even if the app closed as explained in previous answers.

Related

Pass string from C# Code Behind Winforms application to a webpage textbox

I am trying to pass a string from a C# Winforms application to a webpage text box.
The Webpage textbox looks like this:
<input id ="sometext" class = "form-control-sometext clearable"
placholder = "Enter Infor Here" type = "text" name = "moreText">
I have tried several methods such as the following:
//string v = textBoxAutoV.Text;
//string getPage = "http://www.TheWebsite.com?moreText = v;
The information is needed to process an information request and return a string value. I would like to see a code sample if possible. Thank you.
You should try the following way:
protected void Page_Load(object sender, EventArgs e)
{
// Store a value in the Session
Session["moreText"] = "This is an example";
}
<input id ="sometext" class = "form-control-sometext clearable"
placholder = "Enter Infor Here" type = "text" name = "moreText" value=#(Session["moreText"])>
First off, you will need to use an ASP.NET WebForms text box control, if you want to do it the proper way. Here's an example with that:
Here's my code (in mypage.ascx):
<asp:TextBox id ="sometext" class = "form-control-sometext clearable"
placeholder = "Enter Infor Here" type = "text" name = "moreText" runat="server"></asp:TextBox>
And in the code behind (in mypage.ascx.cs):
/// <inheritdoc cref="UserControl.OnInit" />
protected override void OnInit(EventArgs e) {
base.OnInit(e);
sometext.Text = "mytext";
First, let me thank you all. I do not think that I explained it properly, which happens when you are trying not to reveal private information. First, the page that is 'sending' the data is not mypage.ascx ... it is mypage.cs (Winforms, not a web page). Second, the website is not mine. It is a resource. But because it is public, let me lift the veil off it. I am trying to use a site called (www.decodethis.com). It is totally legitimate to use it, but many of my customers that use the site by reference make mistakes when transferring the 17 digit VIN number to the site manually. My idea was to have them enter the information inside the application that I wrote and have it passed to the 'decodthis' page to have it processed and get a result. I am not sure that it is even possible to do this, but since it should not matter to the site owner whether the number to be decoded was entered manually or automatically, it seemed to make sense to do it this way. If it would help. I could make a webpage on my end and then use aspx.cscode to accomplish the same thing if that would work. But I prefer to use the actual application if possible. With that said, all the information about the web text box is visible using the element examination feature. SO ... perhaps using the real-life naming ... could you please suggest a way to accomplish this task (if it can be done at all?). All I want to do is pass the information from the desktop application (main.cs) to the webpage (www.decodethis.com) automatically. Thank you (ALL) again!

CATIA V5 C# how to get AxisSystem from Active Document

I'm trying to update XAxis on Active CATIA document using C#. Anyone knows how to do that? somehowGetActiveAxisSysObject() is placeholder in pseudo code:
Array xMatrix = Array.CreateInstance(typeof(double), 3);
xMatrix.SetValue(5.0, 0);
xMatrix.SetValue(0.0, 1);
xMatrix.SetValue(0.0, 2);
MECMOD.AxisSystem targetAxisSys = **somehowGetActiveAxisSysObject();**
targetAxisSys.PutXAxis(xMatrix);
THANK YOU!
It's been a while since I worked with Catia in C# so the code below may not run properly.
First, I will assume you are working in a part document and that you have created an axis system from the menu: Insert->AxisSystems->AxisSystem (or named something similar). Next, I will also assume that you went into this items properties and renamed it to "Larry".
MECMOD.AxisSystems thisPartsAxisSysCollection = (MECMOD.AxisSystems)Part.AxisSystems;
MECMOD.AxisSystem oneAxisSys = thisPartsAxisSysCollection(1); //Index is name unknown
//or
MECMOD.AxisSystem oneAxisSys = thisPartsAxisSysCollection("Larry");
oneAxisSys.PutXAxis("your data");
If this is not what you are trying to do, but instead are trying to move the part's origin then you will need to access Part.OriginElements instead and use that object's PlaneXY, PlaneYZ, and PlaneZX. Unfortunately those are read only if I remember correctly.

How to gather information from an Input Box from within an Excel Plugin using C#

I have an Excel Add-In on the Ribbon using C# which grabs data from an API, but the password used for the API may change from time-to-time.
Without going into the myriad of security issues that may exist by gathering the PW for this purpose directly within the add-in, I'm not able to even determine how to display an Input Box, much less get user input entered into it and then pass it back to the program.
I have researched the _Application.InputBox Method but can't seem to get that to work. I always get a response such as The name 'InputBox' does not exist in the type '_Application'.
The code at this point is very simple, just:
using Excel = Microsoft.Office.Interop.Excel;
try
{
myToken = RequestToken("name#domain.com", "MyPass");
}
catch
{
Excel._Application.InputBox inputPassword = new Excel.Application.InputBox(); // this is where i get the error
myToken = RequestToken("name#domain.com", inputPassword.value);
}
Again, the purpose here is to try the "default" password. If it fails, ask the user for the updated password (the username won't change) and then we will re-try. Ideally, we'd like to mask the password input, but we can cross that bridge later.
The key here is to not have to re-deploy the entire app with a hard-coded password every time it changes on the server-side.
In a perfect world, I would probably store the updated password somewhere else (.ini file, registry, etc) instead of asking every single time when the "default" password failed. But again, this is a very early first step.
Please keep in mind this is a custom add-in to be used only by a single user, and we are still in testing, so I will probably move to a more robust security method down the road, but for now, this is the best option I have.
Any help will be greatly appreciated.

Is there anyway to fill in a form without user input with .net CF 3.5

I am working with windows ce for an application that needs to be authenticated before use. I don't want the end user to have to enter a username and password which is static everytime the device is turned on. Is there any way to do something like that? I was able to acheive it in a windows form application but i haven't seen anything on Stack or in the MSDN that will help me do that. My code for the forms app is below but it wont work in the Compact Framework.
//string doc = webBrowser1.DocumentText;
//HtmlElement userValue = doc.GetElementById("username");
//userValue.SetAttribute("value", "devacc");
//HtmlElement passValue = doc.GetElementById("password");
//passValue.SetAttribute("value", "zzq15354");
//HtmlElement subButton = doc.GetElementById("submit");
//subButton.InvokeMember("click");
I believe your going to need to verify user/device another way. I would probably save the devices MEID(Dec) # (which is unique) to your user data then allow access if signed in ON that specific hardware.. Here is a thread on how to find that number Find Serial Number

How can you programmatically detect if javascript is enabled/disabled in a Windows Desktop Application? (WebBrowser Control)

I have an application which writes HTML to a WebBrowser control in a .NET winforms application.
I want to detect somehow programatically if the Internet Settings have Javascript (or Active Scripting rather) disabled.
I'm guessing you need to use something like WMI to query the IE Security Settings.
EDIT #1: It's important I know if javascript is enabled prior to displaying the HTML so solutions which modify the DOM to display a warning or that use tags are not applicable in my particular case. In my case, if javascript isn't available i'll display content in a native RichTextBox instead and I also want to report whether JS is enabled back to the server application so I can tell the admin who sends alerts that 5% or 75% of users have JS enabled or not.
Thanks to #Kickaha's suggestion. Here's a simple method which checks the registry to see if it's set. Probably some cases where this could throw an exception so be sure to handle them.
const string DWORD_FOR_ACTIVE_SCRIPTING = "1400";
const string VALUE_FOR_DISABLED = "3";
const string VALUE_FOR_ENABLED = "0";
public static bool IsJavascriptEnabled( )
{
bool retVal = true;
//get the registry key for Zone 3(Internet Zone)
Microsoft.Win32.RegistryKey key = Registry.CurrentUser.OpenSubKey(#"Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3", true);
if (key != null)
{
Object value = key.GetValue(DWORD_FOR_ACTIVE_SCRIPTING, VALUE_FOR_ENABLED);
if( value.ToString().Equals(VALUE_FOR_DISABLED) )
{
retVal = false;
}
}
return retVal;
}
Note: in the interest of keep this code sample short (and because I only cared about the Internet Zone) - this method only checks the internet zone. You can modify the 3 at end of OpenSubKey line to change the zone.
If you are having troubles with popups popping up, i've included a solution for you, and if you want to disable/enable javascript on th client machine (or even just read/query if it is enabled/disabled) ive included that answer for you as well, here we go:
Which popup message do you want to disable? If it's the alert message, try this, obviously resolving the window or frame object to your particular needs, I’ve just assumed top-level document, but if you need an iframe you can access it using window.frames(0). for the first frame and so on... (re the JavaScript part)... here is some code, assuming WB is your webbrowser control...
WB.Document.parentWindow.execScript "window.alert = function () { };", "JScript"
You must run the above code only after the entire page is done loading, i understand this is very difficult to do (and a full-proof version hasn't been published yet) however I have been doing it (full proof) for some time now, and you can gather hints on how to do this accurately if you read some of my previous answers labelled "webbrowser" and "webbrowser-control", but getting back to the question at hand, if you want to cancel the .confirm JavaScript message, just replace window.alert with window.confirm (of course, qualifying your window. object with the correct object to reach the document hierarchy you are working with). You can also disable the .print method with the above technique and the new IE9 .prompt method as well.
If you want to disable JavaScript entirely, you can use the registry to do this, and you must make the registry change before the webbrowser control loads into memory, and every time you change it (on & off) you must reload the webbrowser control out and into memory (or just restart your application).
The registry key is \HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\ - the keyname is 1400 and the value to disable it is 3, and to enable it is 0.
Of course, because there are 5 zones under the Zones key, you need to either change it for the active zone or for all zones to be sure. However, you really don't need to do this if all you want to do is supress js dialog popup messages.
Let me know how you go, and if I can help further.
Here is a suggestion - Encode the warning into your webpage as default. Create a javascript that runs on page load which removes that element. The warning will be there when ever javascript is not allowed to run.
It's a long while since I coded client side HTML javascript to interact with the DOM so I may be a little out of date. i.e. you will need to fix details, but I hope I get the general idea across.
<script>
document.getElemntByID("noJavascriptWarning").innerHTML="";
</script>
and in your HTML body
<DIV id="noJavascriptWarning" name="noJavaScriptWarning">Please enable Javascript</DIV>

Categories

Resources