Vanuston Intelligence Vanuston Intelligence - 2 months ago 11
SQL Question

how to check the value in the email id is correct or not?

When I enter the value inside the

Textbox
and clicking the submit button the entered value should pass to the database and check whether entered text value is valid or not ..

In case entered value is correct the next
div
should be displayed..

<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog modal-sm">
<div class="modal-content" style="width: 500px; margin-left: -24%;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title" style="text-align:center;">Upload image(Max 5Mb)</h4>
</div>
<div class="modal-body">
<asp:Label ID="lblMsg" runat="server"></asp:Label>
<div id="showimage" runat="server">
<asp:TextBox ID="txtHosEmail" runat="server" class="form-control" placeholder="Enter Your Email" Style="border: none;"></asp:TextBox>
<div class="modal-footer">
<%--<button type="button" class="btn btn-sucess" data-dismiss="modal" style="background-color: #79a35a;">Start Upload</button>--%>
<asp:Button ID="btnCheck" runat="server" class="btn btn-default" OnClick="btnCheck_Click" Text="Submit" Style="background-color: #79a35a;" />
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
<div id="hideimage" style="display: none;" runat="server">
<span>Image Name</span>
<asp:TextBox ID="txtimage" runat="server" placeholder="Enter Your Image Name" class="form-control"></asp:TextBox>
<asp:FileUpload ID="fileimage" runat="server" class="form-control inline v-middle input-s" />
<div class="modal-footer">
<%--<button type="button" class="btn btn-sucess" data-dismiss="modal" style="background-color: #79a35a;">Start Upload</button>--%>
<asp:Button ID="btnupload" runat="server" OnClick="btnupload_Click" class="btn btn-default" Text="Start Upload" Style="background-color: #79a35a;" />
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>

</div>
</div>
</div>


Onclick
"btnCheck_Click"
Value is correct the next
hideimage
Div
should be displayed..

protected void btnCheck_Click(object sender, EventArgs e)
{
if (!CheckLogin(txtHosEmail.Text.ToString().Trim()))
{
showimage.Visible = false;
hideimage.Visible = true;
}
else
{
hideimage.Visible = true;
lblMsg.Text = "This Email is InCorrect";
}
}

protected bool CheckLogin(string Email)
{
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand("select Email from PadappaiCheckEmail where Email = '" + Email + "'", con);
cmd.Parameters.Add("@Email", SqlDbType.VarChar).Value = Email;
string id = "";
try
{
con.Open();
id = cmd.ExecuteScalar() == null ? "" : cmd.ExecuteScalar().ToString();
}
catch (Exception ex)
{
//...
}
finally
{
con.Close();
}
if (String.IsNullOrEmpty(id)) return false;
return true;
}

Answer Source

Your if block is the wrong way round.

if (!CheckLogin(txtHosEmail.Text.ToString().Trim()))
{
    showimage.Visible = false;
    hideimage.Visible = true;
}
else
{
    hideimage.Visible = true;
    lblMsg.Text = "This Email is InCorrect";
}

should be:

if (CheckLogin(txtHosEmail.Text.Trim()))
{
    showimage.Visible = false;
    hideimage.Visible = true;
}
else
{
    hideimage.Visible = true;
    lblMsg.Text = "This Email is InCorrect";
}

Note the removal of ! (and also the removal of the unnecessary ToString() call). CheckLogin returns true if the email address is found.