Hello,
I was trying to retrieve data inside a static method and display the data on a non-static label inside a static method. The important thing is, as soon as I type the correct username into the txtUsername, I want the non-static lblemailshow to display the retrieved email inside the static method without clicking a button. I couldn’t get a good solution because all google search says I can’t use non-static control inside a static method. Below is what I tried. Is there anyway that I can call lblemailshow.Text inside a static method?
[WebMethod()]
public static string CheckName(string userName)
{
string returnValue;
try
{
string conString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
SqlConnection conn = new SqlConnection(conString);
SqlCommand cmd = new SqlCommand(@"IF NOT EXISTS(SELECT * FROM Table_1 WHERE Username = @Name)
SELECT 'true'
ELSE
SELECT 'false'", conn);
cmd.Parameters.AddWithValue("@Name", userName.Trim());
SqlDataReader Rder = cmd.ExecuteReader();
conn.Open();
if (Rder.HasRows == true)
Rder.Read();
string Rd_Email = Rder[2].ToString();
lblemailshow.Text = Rd_Email; //
returnValue = Convert.ToString(cmd.ExecuteScalar());
conn.Close();
}
catch (Exception)
{
returnValue = "error";
}
return returnValue;
}
<asp:Panel runat="server">
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Label ID="lblemailshow" runat="server"></asp:Label>
<asp:TextBox ID="txtUsername" runat="server" autocomplete="off" onChange="UsernameAvailability()" onkeyup="UsernameAvailability()"
ondrop="return false;" onpaste="return false;"></asp:TextBox>
<span id="Username_Check"></span>
</ContentTemplate>
<Triggers>
</Triggers>
</asp:UpdatePanel>
</asp:Panel>