I'm trying to bind a list of strings to a datalist. I'm trying to do the binding in a controller and the datalist is in a view(chtml file). I keep getting the error : "The name "datalist id" does not exist in the current context".
Any idea how I can fix this issue?
<input list="cardProgram" class="form-control input-group-lg">
<datalist id="cardProgram" runat="server" />
protected void Page_Load(object sender, EventArgs e)
{
BindCardPrograms(sender, e);
}
private async void BindCardPrograms(object sender, EventArgs e)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:59066/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new
MediaTypeWithQualityHeaderValue("application/json"));
ViewBag.country = "";
HttpResponseMessage response = await
client.GetAsync("api/Profile/InitializeCardProgramSelection");
if (response.IsSuccessStatusCode)
{
List<String> cardPrograms =
response.Content.ReadAsAsync<List<String>>().Result;
var builder = new System.Text.StringBuilder();
foreach (String filename in cardPrograms)
{
builder.Append(String.Format("<option value='{0}'>",
filename));
cardProgram.InnerHtml = builder.ToString();
}
}
/*else
{
return View();
}*/
}
}
Related
I am trying to get data from firebase but it shows an error "Could not cast or convert from System.String to System.Collections.Generic.Dictionary`2"
This is my code:
IFirebaseConfig config = new FirebaseConfig()
{
AuthSecret = "Auth",
BasePath = "Path"
};
IFirebaseClient client;
private void Form1_Load(object sender, EventArgs e)
{
try
{
client = new FirebaseClient(config);
if (client != null)
{
MessageBox.Show("OK");
}
}
catch
{
MessageBox.Show("No");
}
LiveCall();
}
async void LiveCall()
{
while (true)
{
await Task.Delay(1000);
FirebaseResponse res = await client.GetAsync(#"GPS/lat");
Dictionary<string, GPS> data = JsonConvert.DeserializeObject<Dictionary<string, GPS>>(res.Body.ToString());
UpdateRTB(data);
}
}
void UpdateRTB(Dictionary<string, GPS> record)
{
label1.Text += record.ElementAt(1).Key + record.ElementAt(1).Value;
}
Can Anybody help me to solve the problem? thanks!
Here is how my code looks like for the page that has data:
private async Task GetLeaveBalance() {
try
{
Uri = "http://192.168.42.35/API/api/leave/getbalance/"+ empId + "/"+ companyId;
client = new HttpClient();
var authHeaderValue = basic;
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authHeaderValue);
HttpResponseMessage response = await client.GetAsync(Uri);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
var emp = JsonConvert.DeserializeObject<List<Leave>>(responseBody);
dataGrid.ItemsSource = emp;
UserDialogs.Instance.HideLoading();
}
}
catch (HttpRequestException e)
{
Console.WriteLine("\nException Caught!");
Console.WriteLine("Message :{0} ", e.Message);
UserDialogs.Instance.ShowError(e.Message);
}
}
private void Button_Clicked(object sender, EventArgs e)
{
Navigation.PushAsync(new Details());
}
My Second page(Details Page) has a picker which needs to be populated by data that I get from the emp variable so how can I pass data from the first page to the second page(Details Page)?
Considering your approach and code you can directly pass data to the constructor of your second page
List<Leave> leaves = new List<Leave>();
private async Task GetLeaveBalance() {
...
leaves = JsonConvert.DeserializeObject<List<Leave>>(responseBody);
...
}
private void Button_Clicked(object sender, EventArgs e)
{
Navigation.PushAsync(new Details(leaves));
}
You can pass through MessagingCenter aswell, here is some steps.
First in your SecondPage you register an messagingcenter task.
MessagingCenter.Subscribe<SecondPage(you can create a empty interface if you want to use as type),string>(this, "PopulateSecondPage", (sender,DataFromMainPage) =>
{
//your code to handle DataFromMainPage
});
then pass the data using
var page = new SecondPage();
Navigation.PushAsync(page);
MessagingCenter.Send<MainPage>(page, "PopulateSecondPage","Data you want to pass");
I am using inetlab.smpp in c# web app to send sms. A client is created and connected successfully and bound but the message is not delivered to the recipient
public partial class sendsmss : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected async void send_Click(object sender, EventArgs e)
{
SmppClient client = new SmppClient();
await client.Connect("xx.xx.xx.xx", 00000);
if (client.Status == Inetlab.SMPP.Common.ConnectionStatus.Open)
{
await client.Bind("user", "pass");
if (client.Status == Inetlab.SMPP.Common.ConnectionStatus.Open)
{
SubmitSm sm = new SubmitSm();
sm.UserData.ShortMessage = client.EncodingMapper.GetMessageBytes("Test Test Test Test Test Test Test Test Test Test", DataCodings.Default);
sm.SourceAddress = new SmeAddress("1111");
sm.DestinationAddress = new SmeAddress("12345678");
sm.DataCoding = DataCodings.UCS2;
sm.RegisteredDelivery = 1;
await client.Submit(sm);
SubmitSmResp response = await client.Submit(sm);
if (response.MessageId != "")
{
Response.Write("response.messageID is " + response.MessageId.ToString() + "</br> ");
}
else { Response.Write("response null </br> "); }
await client.UnBind();
}
}
}
}
I expect the sms is delivered to recipient
Runs for me perfectly
private async void button1_Click(object sender, EventArgs e)
{
Inetlab.SMPP.SmppClient client = new Inetlab.SMPP.SmppClient();
await client.Connect("x.x.x.x", y);
await client.Bind("systemid", "password", ConnectionMode.Transceiver);
var resp = await client.Submit(
SMS.ForSubmit()
.From("SOURCEADDR", AddressTON.Alphanumeric, AddressNPI.Unknown )
.To("mobilenumber", AddressTON.International, AddressNPI.ISDN)
.Coding(DataCodings.Default)
.Text("test text")
);
if (resp.All(x => x.Header.Status == CommandStatus.ESME_ROK))
{
MessageBox.Show("Message has been sent.");
}
else
{
MessageBox.Show(resp.GetValue(0).ToString());
}
}
I have been trying to delete a data using "DeleteAsync" and it doesn't show anything neither an error, when i hit delete buttom nothing happens.
although things seems fine to me, but you guys help where i missed?
this is the code
private async void Delete(object sender, EventArgs e)
{
private const string weburl = "http://localhost:59850/api/Donate_Table";
var uri = new Uri(string.Format(weburl, txtID.Text));
HttpClient client = new HttpClient();
var result = await client.DeleteAsync(uri);
if (result.IsSuccessStatusCode)
{
await DisplayAlert("Successfully", "your data have been Deleted", "OK");
}
}
Your web API url appears to be wrong as the weburl is set using
private const string weburl = "http://localhost:59850/api/Donate_Table";
var uri = new Uri(string.Format(weburl, txtID.Text));
Note the missing placeholder in the weburl yet it is being used in a string.Format(weburl, txtID.Text
From that it would appear that the weburl was probably meant to be
private const string weburl = "http://localhost:59850/api/Donate_Table/{0}";
so that the id of the resource to be deleted will be part of the URL being called.
Also it is usually suggested that one avoid repeatedly creating instances of HttpClient
private static HttpClient client = new HttpClient();
private const string webUrlTempplate = "http://localhost:59850/api/Donate_Table/{0}";
private async void Delete(object sender, EventArgs e) {
var uri = new Uri(string.Format(webUrlTempplate, txtID.Text));
var result = await client.DeleteAsync(uri);
if (result.IsSuccessStatusCode) {
await DisplayAlert("Successfully", "your data have been Deleted", "OK");
} else {
//should have some action for failed requests.
}
}
I am getting an error "Object Reference is not set to an Instance of an object" in the ContentPage of my MasterPage Facebook Application.
Site.master.cs
public FacebookSession CurrentSession
{
get { return (new CanvasAuthorizer()).Session; }
}
protected void Page_Load(object sender, EventArgs e)
{
var auth = new CanvasAuthorizer { Perms = "email,read_stream,publish_stream,offline_access,user_about_me" };
if (auth.Authorize())
{
ShowFacebookContent();
}
}
private void ShowFacebookContent()
{
var fb = new FacebookClient(this.CurrentSession.AccessToken);
dynamic myInfo = fb.Get("me");
lblName.Text = myInfo.name;
imgProfile.ImageUrl = "https://graph.facebook.com/" + myInfo.id + "/picture";
lblBirthday.Text = myInfo.birthday;
pnlHello.Visible = true;
}
This master Page works OK & displays UserName & ProfilePic.
Default.aspx.cs
SiteMaster myMasterPage;
protected void Page_Load(object sender, EventArgs e)
{
myMasterPage = this.Page.Master as SiteMaster;
}
public void LinkButton1_Click(object sender, EventArgs e)
{
var fb = new FacebookClient(this.myMasterPage.CurrentSession.AccessToken);
dynamic feedparameters = new ExpandoObject();
feedparameters.message = (message_txt.Text == null ? " " : message_txt.Text);
feedparameters.user_message_prompt = "userPrompt";
/*Dictionary<string, object> feedparameters = new Dictionary<string, object>();
feedparameters.Add("message", "Testing Application");
feedparameters.Add("user_message_prompt", "Post To Your Wall");
feedparameters.Add("display", "iframe");*/
dynamic result = fb.Post("me/feed", feedparameters);
}
Even this Page Loads OK but Problem comes when I try to Post using LinkButton.
Following Line gives the error.
var fb = new FacebookClient(this.myMasterPage.CurrentSession.AccessToken);
On LinkButton Click Object Reference is not set to an Instance of an object...
I will really appreciate some help.
Wel finally found what was the problem. Needed to add a hidden field.
<input type="hidden" name="signed_request" value="<%: Request.Params["signed_request"]%>"/>
I think this is neither mentioned any where in the documentation nor in the Provided Samples.