ASP.NET - Userid & Username match

Asked By Rahul
10-Feb-12 07:46 AM
I have memberregister table it has userid and username, in textbox1 i have entered userid and click tab means it want to display username in textbox2 automatically ? how i will put that ?
  Dilip Sharma replied to Rahul
10-Feb-12 07:58 AM
u right code in textchange event of userid text box....

u just pass ur user id and get name  from db base on user id...
and show in text box
  Dilip Sharma replied to Rahul
10-Feb-12 07:59 AM
u write code in textchange event of userid text box....

u just pass ur user id and get name  from db base on user id...
and show in text box 
  [)ia6l0 iii replied to Rahul
10-Feb-12 08:08 AM
You will have to initiate the action that retrieves the username based on user id. And how do you do that?

Client side scripts or handlers.

Either handle it through textchange event of textbox1 - which will go to the server and then in your server , fetch the username based on user id and then from server side assign the new value. 

Or, through pure jquery call a webservice that takes the input as userid and returns the matching username. Check the sample below. 

$(document).ready(function()
{
//textbox1 - change event - associate a handler
$('#<%= this.textbox1.ClientID %>').change(function()
{
//get the user id from the textbox
var userid= $('#<%= this.textbox1.ClientID %>');
//Call the ajax method that takes userid as input and returns the username
$.ajax({
type: "POST",
url: "GetData.aspx/GetUserName",
data: "{'args': '" + userid.val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(e) {
$('#<%= this.textbox2.ClientID %>').val(e.Result);
}
}
}
}


Hope the sample is self -explanatory and helps.
  dipa ahuja replied to Rahul
10-Feb-12 08:18 AM

Markup

 

<asp:UpdatePanel runat="server" ID="up1">

  <ContentTemplate>

ID    <asp:TextBox runat="server" ID="txtID" AutoPostBack="true" OnTextChanged="txtID_Changed" />

    Username:

    <asp:TextBox runat="server" ID="txtuname" />

    <br />

  </ContentTemplate>

</asp:UpdatePanel>

 

Code Behind:

  
protected void TxtID_Changed(object sender, EventArgs e)
{
  txtuname.Text = checkExist(txtID.Text);
}
 
public string checkExist(string s)
{
  SqlConnection conn = new SqlConnection("connstring");
  SqlCommand comm = new SqlCommand("SELECT name from table1 where id=" + s, conn);
  conn.Open();
  string uname = comm.ExecuteScalar().ToString();
  conn.Close();
  return uname;
}

  Reena Jain replied to Rahul
10-Feb-12 08:30 AM
hi,

For that you have to pass search key i.e. userid in select statement, after that based on where condition you can get username present in table like this.
try this code on textchange even to textbox -

protected void textchange(object sender, EventArgs e)
{
 
SqlConnection con = new SqlConnection("con string ");
SqlDataAdapter da;
string mySQL = "SELECT username FROM emptable where UserId=" + TxtUserid.Text + " ";
da = new SqlDataAdapter(mySQL, con);
con.Open();
DataSet ds = new DataSet();
da.Fill(ds);
 
if(ds.Tables[0].Rows.Count>0)
{
textusername.Text=ds.Tables[0].Row[0]["UserName"].ToString();
}
 
}

  kalpana aparnathi replied to Rahul
10-Feb-12 02:03 PM
hi,

Try this code

<input type="text" id="userid"/>
<input type="text" id="userName"/>

<script type="text/javascript">
$
(function(){
  $
("#userid").change(function(){
   $
("#userName").val($(this).val());
 
});
})
</script>
Create New Account
help
Net hi friends Any one send frequently asked Important questions in C# .Net, ADO .Net, Asp .Net and Sql Server. . . . . . . . tx in Advance. . . . . . Hi, Find this. . (B)What is an IL? (B A) What is scavenging? (B) What are different types of caching using cache object of ASP.NET? (B) How can you cache different version of same page using ASP.NET cache object? (A) How will implement Page Fragment Caching? (B) Can you compare ASP.NET sessions with classic ASP? (B) Which are the various modes of storing ASP.NET session
duplicated Customer Information in your query result. If you are using the query result for ASP.NET application, all you need to to is to query each table seperatedly and fill them Customer Information from displaying multiple times). Hazel, Yes, you are correct. This is for a asp.net 2.0 application. I think you are correct. I was figuring that no matter what relations among them However, you can still do the VS 2003 way: dim conn as SqlConnection = new SqlConnection([Your Connections String]) dim ds as new DataSet dim daTable1 as new SqlDataAdapter dim daTable2 as new SqlDataAdapter dim daTable3 as new SqlDataAdapter dim daTable4 as new SqlDataAdapter daTable1.SelectCommand = "select * from table1
v4.dbtutorials.com / sql / binding-a-menu-navigation-control-to-an-xml-sitemap-file-in-asp-net / Hope This will help you HI try this Horizontal Menu: Vertical Menu: <? xml version = " 1 Some new products " / > < / siteMapNode > < siteMapNode title = " Services" description = " Our Services" > < siteMapNode url = " Service1.aspx" title = " ASP.NET Consulting" description = " Best ASP.NET Consulting" / > < siteMapNode url = " Service2.aspx" title = " ASP.NET Training" description = " Best ASP.NET Training" / > < / siteMapNode > < / siteMapNode > < / siteMap > private void CreateMenuControl() { Menu1.DataSource = GetSiteMapDataSource
ASP.NET Caching Basics ASP.NET Caching Basics by Peter A. Bromberg, Ph.D. Peter Bromberg "If people had understood how Caching? Caching is one of the least used and misunderstood, yet most powerful features of ASP.NET - - both in the 1.1 flavor, and even more so in ASP.NET 2.0. Most developers do not get into the details of harnessing the power of
using LINQ in asp.net 3.5 ASP.NET hi friends, please give using LINQ in asp.net 3.5 examples, eg: table employee fields eid, ename, esal how to write asp.net using LINQ. please give the steps and code, thanks. you can right it like this