//Método para realizar a busca do endereço enviada por ajax //Json -> JavaScript Object Notation public JsonResult PesquisarEndereco(string cep) { string dados = string.Empty; //vazio try { Address endereco = BuscaCep.GetAddress(cep); dados = endereco.Street + ", " + endereco.District + ", " + endereco.City + ", " + endereco.State; } catch (Exception e) { dados = e.Message; //mensagem de erro } return(Json(dados)); //Hello World }
private void button1_Click(object sender, EventArgs e) { try { Address address = BuscaCep.GetAddress(textBox5.Text); textBox1.Text = address.Street; textBox2.Text = address.District; textBox3.Text = address.City; textBox4.Text = address.State; } catch (Exception ex) { label1.Text = ex.Message; label1.Visible = true; } }
protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { try { // Busca o CEP nos Correios pela API Address address = BuscaCep.GetAddress(this.txtCep.Value); this.txtEnd.Value = address.Street; this.txtBairro.Text = address.District; this.txtCidade.Value = address.City; this.txtUf.Text = address.State; this.lblmensagem1.Text = ""; } catch { this.lblmensagem1.Text = "<font color='#FF0000'>ERRO: CEP Informado e Incorreto !!!</font>"; } }