I have several DialogFragement's in my app that I need to transition to Android.Support.V4.App.DialogFragment so my app is compatible with API 29 (Q). I began by converting my "Change Password" dialog fragment code to this:
class ChangePassword : Android.Support.V4.App.DialogFragment
{
public event DialogEventHandler Dismissed;
public string selection = "";
private int error = 0;
public User MyUser;
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView(inflater, container, savedInstanceState);
View view = inflater.Inflate(Resource.Layout.ChangePassword, container, false);
Button ok = view.FindViewById<Button>(Resource.Id.button_ok);
EditText currentPassword = view.FindViewById<EditText>(Resource.Id.currentPassword);
EditText newPassword1 = view.FindViewById<EditText>(Resource.Id.newPassword1);
EditText newPassword2 = view.FindViewById<EditText>(Resource.Id.newPassword2);
ok.Click += (sender, args) =>
{
if (currentPassword.Text != "" && (newPassword1.Text.ToUpper () == newPassword2.Text.ToUpper()) && (newPassword1.Text != "" || newPassword2.Text != ""))
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
OMLDataInterfaceWeb.OMLDataInterface datainterface = new OMLDataInterfaceWeb.OMLDataInterface();
try
{
datainterface.ChangeUserPassword(MyUser.Username, currentPassword.Text, newPassword1.Text);
}
catch (Exception e)
{
error = 1;
Utils.showMessage(e.Message, "Error");
}
if (error == 0)
{
selection = newPassword2.Text;
if (null != Dismissed)
Dismissed(this, new DialogEventArgs { Selection = selection });
}
}
else
{
if (currentPassword.Text == "")
{
// Android.Content.Context context = new AppContext() ;
Utils.showMessage("Enter the current password.","ERROR");
}
else
{
if (newPassword1.Text == "")
{
Utils.showMessage("The first new password field is blank.", "ERROR");
} else if (newPassword2.Text == "")
{
Utils.showMessage("Please re-enter the new password.", "ERROR");
} else if (newPassword1.Text.ToUpper() != newPassword2.Text.ToUpper())
{
Utils.showMessage("The passwords do not match.", "ERROR");
}
}
}
};
return view;
}
public override void OnResume()
{
int width = 900;
int height = 900;
Dialog.Window.SetLayout(width, height);
base.OnResume();
}
}
Note that I'm using Android.Support.V4.App.DialogFragment as opposed to the Android.App.DialogFragment.
I call this from another activity with a button click, that code is:
btnChangePassword.Click += (sender, e) =>
{
Android.Support.V4.App.FragmentTransaction transcation = FragmentManager; //FragmentManager; // FragmentManager.BeginTransaction();
ChangePassword changePassword = new ChangePassword();
changePassword.MyUser = MyUser;
changePassword.Show(transcation, "Dialog");
changePassword.Dismissed += (s, a) => {
/* do something with e.Selection here */
if (a.Selection.ToUpper() != "")
{
ChangePassword _exportFragment = (ChangePassword)FragmentManager.FindFragmentByTag("Dialog");
if (_exportFragment != null)
{
_exportFragment.Dismiss();
}
changedPassword = true;
thePassword = a.Selection;
}
else
{
Toast.MakeText(this, "Enter new password.", ToastLength.Long).Show();
}
};
};
I'm getting two errors in the button click code, the first is Cannot implicitly convert type 'Android.App.FragmentManager' to 'Android.Support.V4.App.FragmentTransaction which occurs on this line of code Android.Support.V4.App.FragmentTransaction transcation = FragmentManager;, assuming that I also had to qualify FragmentManager with Android.Support.V4.App., I changed the code to read Android.Support.V4.App.FragmentTransaction transcation = Android.Support.V4.App.FragmentManager;, this generated the error 'FragmentManager' is a type, which is not valid in the given context, the other error Im getting is Cannot convert type 'Android.App.Fragment' to 'MyAndroidApp.ChangePassword' which occurs on the line ChangePassword _exportFragment = (ChangePassword)FragmentManager.FindFragmentByTag("Dialog");. I've searched all ove for an answer and nothing I've tried has resolved this. What am I missing?
I was able to figure it out. The new button click code is:
btnChangePassword.Click += (sender, e) =>
{
Android.Support.V4.App.FragmentTransaction transcation = SupportFragmentManager.BeginTransaction();
ChangePassword changePassword = new ChangePassword();
changePassword.MyUser = MyUser;
changePassword.Show(transcation, "Dialog");
changePassword.Dismissed += (s, a) => {
/* do something with e.Selection here */
if (a.Selection.ToUpper() != "")
{
ChangePassword _exportFragment = (ChangePassword)SupportFragmentManager.FindFragmentByTag("Dialog");
if (_exportFragment != null)
{
_exportFragment.Dismiss();
}
changedPassword = true;
thePassword = a.Selection;
}
else
{
Toast.MakeText(this, "Enter new password.", ToastLength.Long).Show();
}
};
Related
currently i am working a one project and i got this type of error.
i excuted the procedure and in debugging mode prcedure pass the data to entity file but when i go back to aspx page so that time i got this null exception.
how can i resolve.
any one help me?.
UserDAL file
this is a prcedure
public UserENT PR_IP_User_LoginUser(SqlInt32 UserID)
{
using (SqlConnection objconn = new SqlConnection(ConnectionString))
{
objconn.Open();
using (SqlCommand objcmd = objconn.CreateCommand())
{
try
{
#region Prepaed Command
objcmd.CommandType = CommandType.StoredProcedure;
objcmd.CommandText = "PR_IP_User_LoginUser";
objcmd.Parameters.AddWithValue("#UserID", UserID);
#endregion
UserENT entuser = new UserENT();
#region Read and set controls
using (SqlDataReader objSDR = objcmd.ExecuteReader())
{
while (objSDR.Read())
{
if (!objSDR["User_Name"].Equals(DBNull.Value))
{
entuser.User_Name = Convert.ToString(objSDR["User_Name"].ToString().Trim());
}
if (!objSDR["Password"].Equals(DBNull.Value))
{
entuser.Password = Convert.ToString(objSDR["Password"].ToString().Trim());
}
if (!objSDR["User_ID"].Equals(DBNull.Value))
{
entuser.User_ID = Convert.ToInt32(objSDR["User_ID"]);
}
if (!objSDR["ContactNo"].Equals(DBNull.Value))
{
entuser.ContactNo = Convert.ToString(objSDR["ContactNo"]);
}
if (!objSDR["Email_ID"].Equals(DBNull.Value))
{
entuser.Email_ID = Convert.ToString(objSDR["Email_ID"]);
}
if (!objSDR["Is_Admin"].Equals(DBNull.Value))
{
entuser.Is_Admin = Convert.ToBoolean(objSDR["Is_Admin"]);
}
}
return entuser;
}
#endregion
}
catch (Exception e)
{
Message = e.InnerException.Message;
return null;
}
finally
{
objconn.Close();
}
}
}
}
#endregion
on client side or can say aspx page
on button click event
protected void btnLogin_Click(object sender, EventArgs e)
{
#region Server Side Validation
String strerr = "";
if (txtusername.Text.Trim() == "")
{
strerr += "Enter UserName";
}
if (txtpassword.Text.Trim() == "")
{
strerr += "Enter Password";
}
if (strerr != "")
{
lblMessage.EnableViewState = true;
lblMessage.Text = strerr;
}
#endregion
#region Gather Data
SqlString Username, userpass;
if (txtusername.Text.Trim() != "")
{
Username = txtusername.Text.Trim();
}
if (txtpassword.Text.Trim() != "")
{
userpass = txtusername.Text.Trim();
}
#endregion
UserBAL baluser = new UserBAL();
UserENT entuser = new UserENT();
SqlInt32 UserID_Res;
SqlString User_name_res, User_Password_res;
SqlInt32 userid = Convert.ToInt32(txtuserid.Text.Trim());
if (Request.QueryString["User_ID"] == null)
{
if (baluser.Login(userid) != null)
{
User_name_res = entuser.User_Name.Value.ToString().Trim();
UserID_Res = Convert.ToInt32(entuser.User_ID.Value);
User_Password_res = entuser.Password.Value.ToString().Trim();
if (User_name_res == txtusername.Text.Trim() || User_Password_res == txtpassword.Text.Trim())
{
Response.Redirect("AddSubject.aspx");
}
else
{
Response.Redirect("AddTopic.aspx");
}
}
}
#endregion
The C# code associated with a ".aspx" page (or code behind) is executed on the server side.
I assume that UserBAL.Login() function returns the user's data once logged in. It may be necessary to get the returned object.
On button click event :
protected void btnLogin_Click(object sender, EventArgs e)
{
...
UserENT entuser = baluser.Login(userid);
if (entuser != null)
{
...
Thanks every one who help to solve my error. now i resolve my error.
i Just pass the data to procure and check the data in procedure and return
Boolean value.
Thanks Again :)
I have a function called SetActionSection() which i placed in my pageload. I'm expecting it to be called but nothing happens. I get the result I want when I reload the page.
Here's the my pageload
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string fullName = GetUserFullName();
string id = Request.QueryString["id"];
TextBoxProjectManager.Text = fullName;
if (id != null)
{
GetCMMDetails(TextBoxProjectManager.Text);
int valid = ValidateUserAccess(id, fullName);
if (valid > 0)
GetProjectPostEval();
else
{
Response.Write("You are not allowed to access this data.");
ActionSection.Visible = false;
}
}
else
{
TextBoxProjectManager.Text = fullName;
GetCMMDetails(fullName);
}
SetActionSection();
}
}
Here is SetActionSection() function which shows the a button based on the status in the database.
private void SetActionSection()
{
string id = Request.QueryString["id"];
if (id == null)
{
LinkButtonSaveDraft.Visible = true;
LinkButtonSubmit.Visible = true;
ActionSection.Visible = true;
return;
}
string status = GetStatus(id);
string projectManager = GetCMM(id, "ProjectManager");
string buco = GetCMM(id, "Buco");
string businessExecutiveOfficer = GetCMM(id, "BusinessExecutiveOfficer");
string i2lFunctionLead = GetCMM(id, "I2LFunctionLead");
string user = GetUserFullName();
if ((status.Equals("Draft", StringComparison.OrdinalIgnoreCase))
&& user.Equals(projectManager, StringComparison.OrdinalIgnoreCase))
{
Response.Write(status + " Draft");
LinkButtonSaveDraft.Visible = true;
LinkButtonSubmit.Visible = true;
ActionSection.Visible = true;
}
if (status.Equals("Submitted", StringComparison.OrdinalIgnoreCase) &&
user.Equals(buco))
{
Response.Write(status + " Submitted");
LinkButtonSaveDraft.Visible = false;
LinkButtonSubmit.Visible = false;
LinkButtonBUCOApprove.Visible = true;
ActionSection.Visible = true;
}
if (status.Equals("(Approved) - BUCO", StringComparison.OrdinalIgnoreCase) &&
user.Equals(businessExecutiveOfficer))
{
Response.Write(status + " (Approved) - BUCO");
LinkButtonBUCOApprove.Visible = false;
LinkButtonBEOApprove.Visible = true;
}
if (status.Equals("(Approved) - BEO", StringComparison.OrdinalIgnoreCase) &&
user.Equals(businessExecutiveOfficer))
{
Response.Write(status + " (Approved) - BEO");
LinkButtonBEOApprove.Visible = false;
LinkButtonI2LFunctionLeadApprove.Visible = true;
}
if (status.Equals("(Approved) - I2L Function Lead", StringComparison.OrdinalIgnoreCase))
{
Response.Write(status + " (Approved) - I2L Function Lead");
LinkButtonI2LFunctionLeadApprove.Visible = false;
}
}
I have tested the SetActionSection method and it works. I just want it to be called when the user clicks the submit button. By the way. I'm redirecting to the same form.
Anything inside your if(!IsPostBack) condition will only be executed on initial load and not on submit. You could put the code you want to run on submit (postback) inside an else if you want
if (!IsPostBack)
{
....
}
else
{
SetActionSection();
}
https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.page.ispostback?view=netframework-4.8
Or put your code inside a button click event
I have an active Google Places autocomplete working with Xamarin Forms or Cross Platform. I have a working solution that auto populates the address when the user types in the address. My problem is when the user selects it from the list the address does not go to the search_bar.text… The search bar just remains with the text that was typed? how can I get the text when selected to populate in the search bar.
I am new to Xamarin forms and C#.
public Createbusinessaccount ()
{
InitializeComponent ();
search_bar.ApiKey = GooglePlacesApiKey;
search_bar.Type = PlaceType.Address;
search_bar.Components = new Components("country:us"); // Restrict results to Australia and New Zealand
search_bar.PlacesRetrieved += Search_Bar_PlacesRetrieved;
search_bar.TextChanged += Search_Bar_TextChanged;
search_bar.MinimumSearchText = 2;
results_list.ItemSelected += Results_List_ItemSelected;
}
void Search_Bar_PlacesRetrieved(object sender, AutoCompleteResult result)
{
results_list.ItemsSource = result.AutoCompletePlaces;
spinner.IsRunning = false;
spinner.IsVisible = false;
if (result.AutoCompletePlaces != null && result.AutoCompletePlaces.Count > 0)
results_list.IsVisible = true;
}
void Search_Bar_TextChanged(object sender, TextChangedEventArgs e)
{
if (!string.IsNullOrEmpty(e.NewTextValue))
{
results_list.IsVisible = false;
spinner.IsVisible = true;
spinner.IsRunning = true;
}
else
{
results_list.IsVisible = true;
spinner.IsRunning = false;
spinner.IsVisible = false;
}
}
async void Results_List_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
if (e.SelectedItem == null)
return;
var prediction = (AutoCompletePrediction)e.SelectedItem;
results_list.SelectedItem = null;
var place = await Places.GetPlace(prediction.Place_ID, GooglePlacesApiKey);
if (place != null)
await DisplayAlert(
place.Name, string.Format("Lat: {0}\nLon: {1}", place.Latitude, place.Longitude), "OK");
}
In your ItemSelected method, you need to set the text of the searchbar:
async void Results_List_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
if (e.SelectedItem == null)
return;
var prediction = (AutoCompletePrediction)e.SelectedItem;
search_bar.Text = prediction.Name? // Your property here
results_list.SelectedItem = null;
var place = await Places.GetPlace(prediction.Place_ID, GooglePlacesApiKey);
if (place != null)
await DisplayAlert(
place.Name, string.Format("Lat: {0}\nLon: {1}", place.Latitude, place.Longitude), "OK");
}
I am still trying to fix this, it only adds the street name and number not the whole address
When closing Form containing a WebBrowser control with a Pdf document open in the webbrowser, the form takes some 10 seconds to close. I tracked the issue down to Dispose method of the webbrowser.
private void advBandedGridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
{
if (advBandedGridView1.GetFocusedDataRow() != null)
{
string wordno = advBandedGridView1.GetFocusedDataRow()["wordno"].ToString();
string itemcd = advBandedGridView1.GetFocusedDataRow()["itemcd"].ToString();
for (int i = 0; i < _caseCount; i++)
{
ButtonColoring(wordno, _seqkindCode[i]);
}
LoadPDF(itemcd);
gridControl2.DataSource = null;
gridControl2.RefreshDataSource();
}
}
Control Event
private void LoadPDF(string itemcd)
{
try
{
ReturnPacket rp;
rp = new Q3i.POP.BIZ.Common.CommonCode().SelectCommonCodeFull("603", "kind3 = 'EYE'", false);
if (rp.DataTables.Count > 0 && rp.DataTables[0].Rows.Count == 0)
{
rp = new Q3i.POP.BIZ.Common.CommonCode().SelectCommonCodeFull("603", "kind3 = '1'", false);
}
if (rp.DataTables[0].Rows.Count > 0)
{
string dockind = string.Empty;
dockind = rp.DataTables[0].Rows[0]["code"].ToString();
ParameterCollection paramCol = new ParameterCollection();
paramCol.Add("p_itemcd", itemcd);
paramCol.Add("p_dockind", dockind);
PdfFileInfo temp_fileInfo = biz.SelectInspectionStandards(paramCol);
if (temp_fileInfo != null)
{
if (_fileInfo != null && temp_fileInfo.FileNm == _fileInfo.FileNm)
{
WebBrowserPdf.Visible = true;
return;
}
_fileInfo = null;
_fileInfo = temp_fileInfo;
PDF_FILE_PATH = FilePath + _fileInfo.FileNm;
DirectoryInfo di = new DirectoryInfo(FilePath);
if (di.Exists == false)
{
di.Create();
}
if (!File.Exists(PDF_FILE_PATH))
File.WriteAllBytes(PDF_FILE_PATH, _fileInfo.FileData);
if (!PDF_FILES.Contains(PDF_FILE_PATH))
{
PDF_FILES.Add(PDF_FILE_PATH);
}
WebBrowserPdf.Navigate(PDF_FILE_PATH + "?#zoom=" + _zoomFactor + "%", false);
WebBrowserPdf.Visible = true;
simpleButtonOpenPOPUP.Enabled = true;
}
else
{
WebBrowserPdf.Visible = false;
simpleButtonOpenPOPUP.Enabled = false;
}
}
}
catch (Exception ex)
{
UCXtraMsgBox.ShowDialog(ex.Message, "m0146", Q3i.Common.Enums.MsgBoxButton.OK, Q3i.Common.Enums.MsgBoxIcon.Alert, true);
}
}
it is Load Method
private void w_pcmu081_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
WebBrowserPdf.Dispose();
Process[] Pro = Process.GetProcessesByName("osk");
if (Pro.GetLength(0) > 0)
Pro[0].Kill();
}
catch(Exception ex)
{
UCXtraMsgBox.ShowDialog(ex.Message, "m0146", Q3i.Common.Enums.MsgBoxButton.OK, Q3i.Common.Enums.MsgBoxIcon.Info, true, null, true);
}
}
Closing
The same situation happened to me.
Adobe has done something wrong in the latest version of Acrobat Reader DC (15.023.20056).
If you uncheck option Enable Protected Mode at startup in Edit -> Preferences -> Security (Enhanced), everything will be back to normal.
On my case it is not a solution.
More info here: https://forums.adobe.com/thread/2267688
I have userControl(wpf)
public WebBrowserControl()
{
InitializeComponent();
_Browser = new WebBrowser();
_pipeClient = new NamedPipeClient<WebMessage>("TestPipe");
_pipeClient.ServerMessage += PipeClientOnServerMessage;
_pipeClient.Error += PipeClientOnError;
_pipeClient.Start();
InternetExplorerBrowserEmulation.SetBrowserEmulationMode();
SuppressScriptErrors(_Browser, false);
SetWebBrowserFeatures();
GridBrrw.Children.Add(_Browser);
_Browser.ObjectForScripting = new ObjectForScripting(_pipeClient);
_Browser.LoadCompleted += new LoadCompletedEventHandler(_Browser_OnLoadCompleted);
_Browser.Navigating += _Browser_OnNavigating;
var th = new Thread(ExecuteInForeground);
th.Start();
}
private void ExecuteInForeground()
{
int i = 0;
while (i<=9)
{
Thread.Sleep(1000);
_pipeClient.PushMessage(new WebMessage() {Actions = "allo"});
i++;
}
}
private void _Browser_OnNavigating(object sender, NavigatingCancelEventArgs e)
{
if (IsClick)
{
var mes = new WebMessage { Actions = "OpenUrl" };
mes.Url = e.Uri.AbsoluteUri;
_pipeClient.PushMessage(mes);
e.Cancel = false;
}
return;
e.Cancel = false;
}
private void _Browser_OnLoadCompleted(object sender, NavigationEventArgs e)
{
try
{
var br = sender as WebBrowser;
if (br?.Source != null && br.Source.AbsoluteUri != e.Uri.AbsoluteUri)
{
MessageBox.Show($"Source = {br.Source.AbsoluteUri},\r\n AbsoluteUri = {e.Uri.AbsoluteUri}");
return;
}
Document = (HTMLDocument)br.Document;
if (!string.IsNullOrEmpty(FindElement))
{
var node = HtmlNode.CreateNode(FindElement);
while (GetElement(node) == null)
{
System.Windows.Forms.Application.DoEvents();
}
}
if (WaitAjax)
{
ConnectToAjax();
return;
}
if (Sleep > 0)
{
var time = TimeSpan.FromSeconds(Sleep);
Thread.Sleep(time);
}
var mes = new WebMessage { Actions = "Load" };
mes.Title = Document.title;
mes.Url = br.Source.AbsoluteUri;
mes.Domain = br.Source.Host.Replace("http", "").Replace("http://", "").Replace("https://", "").Replace("https", "");
mes.Fovicon = $"http://www.google.com/s2/favicons?domain={mes.Domain}";
if (Document != null)
{
var htmls = Document.getElementsByTagName("html");
if (htmls != null && htmls.length > 0)
{
var html = htmls.item(0) as IHTMLElement;
mes.Html = html.outerHTML;
}
}
_pipeClient.PushMessage(mes);
}
catch (Exception ex)
{
throw ex;
}
}
Event Navigating firing, ExecuteInForeground sends messages, but LoadCompleted event is not firing. Could this be due to the settings window - Property = "ResizeMode" Value = "NoResize". What am I doing wrong?