Bootstrap Button_Click Event Not Firing - c#

I have a form designed with a button which should call a stored procedure. For now, I just want the button to display text in a textbox (just to make sure the button is working). However, I cannot get it to fire the button_click event.
Here is what I have:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div class="container-fluid">
<section class="container">
<div class="container-page">
<div class="col-md-6">
<h3 class="dark-grey">Registration</h3>
<div class="form-group col-lg-12">
<label>Username</label>
<input type="" name="" class="form-control" id="" value="">
</div>
<div class="form-group col-lg-6">
<label>Password</label>
<input type="password" name="" class="form-control" id="" value="">
</div>
<div class="form-group col-lg-6">
<label>Repeat Password</label>
<input type="password" name="" class="form-control" id="" value="">
</div>
<div class="form-group col-lg-6">
<label>Email Address</label>
<input type="" name="" class="form-control" id="" value="">
</div>
<div class="form-group col-lg-6">
<label>Repeat Email Address</label>
<input type="" name="" class="form-control" id="" value="">
</div>
<div class="col-md-6">
<h3 class="dark-grey">Terms and Conditions</h3>
<p>
By clicking on "Register" you agree to the Terms and Conditions.
</p>
<button type="submit" class="btn btn-primary" onclick="btnSumbit_Click">Register</button>
<br />
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</div>
</section>
</div>
</form>
</body>
</html>
My c# code is:
protected void btnSumbit_Click(object sender, EventArgs e)
{
TextBox1.Text = "Registered";
}
Any idea why this will not work?

My guess is that you are getting a normal <button> mixed up with an <asp:Button>.
Your current implementation wants to run a javascript function name btnSubmit_Click and does not have any connection to your C# code-behind.
...
<asp:Button type="submit" CssClass="btn btn-primary" OnClick="btnSumbit_Click" runat="server">Register</asp:Button>
...
I haven't been able to test if it works myself.

If you need to use an html button, instead of an ASP Button control (for instance, if you need something other than text in the button), you can still do it like this (using runat=server and OnServerClick):
<button runat="server" type="button" id="updateButton" onserverclick="UpdateEmail_Click" class="btn btn-success btn-block" title="<%$ Resources:UserMessages, UpdateCaps %>"><asp:Localize ID="Localize5" runat="server" Text="<%$ Resources:UserMessages, UpdateCaps %>"></asp:Localize></button>

If you're using a standard HTML button, you need to:
Add runat="server" to your button.
Set your button to use onserverclick instead of onclick.
http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlbutton.onserverclick(v=vs.110).aspx
So:
<button runat="server" class="btn btn-primary" onserverclick="Method_Name"...
Alternatively, you can use Bootstrap classes with the <asp:Button... tags as well. You'll simply apply them to an attribute called CssClass instead of `class'.
So:
<asp:Button type="submit" runat="server" CssClass="btn btn-primary" OnClick="Method_Name"...

Related

Signature Pad Using C# Code Behind Will Not Allow Signature Insertion

#szimek I am trying to implement your Signature Pad in a C# Web Forms application. The signature pad displays and the Clear button is clickable, but the canvas won't open up to allow entry of the signature. I have had to change signature-pad ID to signaturepad, could that be the reason it isn't working? HELP!!
</div>
<hr class="double" />
<asp:HiddenField ID="hfimg" runat="server" />
<div id="signaturepad" class="signature-pad" runat="server">
<div class="signature-pad--body" runat="server">
<canvas></canvas>
</div>
<div class="signature-pad--footer" runat="server">
<div class="description">Sign above</div>
<div class="signature-pad--actions" runat="server">
<div>
<button type="button" class="button clear" data-action="clear">Clear</button>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/signature_pad#4.0.0/dist/signature_pad.umd.min.js"></script>
<script src="Content/app.js"></script>

Error CS0411 ASP.NET Core Web Application

I'm currently working on a project for one of my classes and I suddenly received this error when I tried to run it:
Severity Code Description Project File Line Suppression State
Error
CS0411 The type arguments for method 'IModelExpressionProvider.CreateModelExpression<TModel, TValue>(ViewDataDictionary, Expression<Func<TModel, TValue>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly. Proj1BankApp C:\Users\jross.000\source\repos\Proj1BankApp\Views\Home\Index.cshtml 1 Active
Visual Studio Screenshot
It directs me to my Index.cshtml file but nothing else and I don't know how to fix it, so any help would be appreciated.
Index.cshtml:
#model BankAppModel
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body style="height: 50px">
<form id="form1" runat="server">
<h1>#ViewBag.Title</h1>
<div class="row">
<label asp-for="Name" class="control-label col-sm-3">Name: </label>
<input asp-for="Name" class="form-control col-sm-3" />
<span asp-validation-for="#Model.Name" class="text-danger col"></span>
</div>
<div class="row">
<label asp-for="TransactionMonth" class="control-label col-sm-3">Month: </label>
<input asp-for="TransactionMonth" class="form-control col-sm-3" />
<span asp-validation-for="#Model.TransactionMonth" class="text-danger col"></span>
</div>
<div class="row">
<label asp-for="TransactionDay"class="control-label col-sm-3">Day: </label>
<input asp-for="TransactionDay" class="form-control col-sm-3" />
<span asp-validation-for="#Model.TransactionDay" class="text-danger col"></span>
</div>
<div class="row">
<label asp-for="TransactionYear" class="control-label col-sm-3">Year: </label>
<input asp-for="TransactionYear" class="form-control col-sm-3" />
<span asp-validation-for="#Model.TransactionYear" class="text-danger col"></span>
</div>
<div class="row">
<label class="control-label col-sm-3">Balance: </label>
<input class="form-control col-sm-3" name="balance" readonly />
</div>
<div class="row">
<input class="col offset-sm-3 pl-0" type="submit" name="deposit" value="Deposit" asp-for="Deposit" formmethod="post" />
<input class="col offset-sm-3 pl-0" type="submit" name="withdraw" value="Withdraw" asp-for="Withdraw" formmethod="post" />
<input class="btn btn-secondary" asp-action="Index" type="submit" name="clear" value="Clear" formmethod="post" />
</div>
</form>
</body>
</html>
In my case there was a hidden input property was declared, which was not declared in model class, so i removed that hidden input and error was gone,
this happens when you copy paste the code from another form. than you.
This is likely on a line like InputFor(m=> m.Something)
Actual method you're calling has generic arguments, like Method<T>(T arg1, ..) and the compiler attempts to infer them by looking at the types (the class) of the arguments you pass in..
for example: if you call a method with signature Method<T>(T value) as Method("hi") the compiler is smart enough to figure out this is actually Method<string>("hi")
But this doesn't always work, for example if the type of the argument cannt be resovled at compile time.
You likely have to find this call in your cshtml file and either add the type <typehere> manually or you may have a different compile error in your code which prevents the compiler from resolving this type.
Try scrolling down to the bottom of the error list and see if there are any other errors you can resolve. If not, look for the above.

Login Boostrap Modal on MasterPage

I have a Login & Register Boostrap Modal on my MasterPage.
The code is simple and works. The problem comes when user make an invalid use.
I have all validations on code behind, when user hit Login i need if its invalid, a Label show the error and popup keep alive. My Popup close everytime user hit Login, its ok or not. I tested some similar scenary in Content Pages, with registerstartupclient to call a function ShowModal, that reopen the modal. But i cant do that on MasterPage. So how can i validate input data and show a label without close the popup.
Im running Modal on Form Tag from Body because MasterPages dont allow more than one.
My Project is ASP.Net C# WebForms.
<div id="logmodal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal contenido-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title"><i class="fa fa-user-circle"> </i> Login</h4>
</div>
<div class="modal-body">
<%--<form id="Conectar">--%>
<div class="form-group">
<input type="text" id="txtUsuario" class="form-control" runat="server" placeholder="Usuario Web"/>
</div>
<div class="form-group">
<input type="password" id="txtPassword" class="form-control" runat="server" placeholder="Password"/>
</div>
<div class="form-group">
 <asp:Button ID="Button1" runat="server" Text="LOGIN" CssClass="btn btn-default" OnClick="Button1_Click" />
</div>
<%--</form>--%>
<asp:Label ID="LblErrors" runat="server" Text=""></asp:Label>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" >Cerrar</button>
</div>
</div>
</div>
</div>

Invoking server side function from the client side for dynamically created markup

I want to call a method that is on the server side by clicking a link or a button that is being dynamically created on the server side. My code dynamically generates the html and changing it to static html is not an option.
str.Append("<a data-toggle=\"modal\" href=\"#cmpModal\" class=\"btn btn-danger\">" + Resources.vsk.addasfriend + "</a> | ");
The line above creates a link which upon click opens up a model, the code for which is as follows:
<div class="modal fade" id="cmpModal">
<div class="modal-dialog">
<div class="modal-content">
<div id="acategory" class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="actxt">Add to Friend List</h4>
</div>
<div class="model-body">
<div class="pd_10">
<div role="form">
<fieldset>
<div class="form-group">
<label class="col-sm-4 control-label" for="<%= txt_message.ClientID %>">
<%= Resources.vsk.message_channel_10 %>:</label>
<div class="col-sm-8">
<asp:TextBox CssClass="form-control" ID="txt_message" onkeyup="Count_Chars(this,'#tabout_cnt',100);" runat="server"
TextMode="MultiLine" Height="50px"></asp:TextBox><br />
<strong id="tabout_cnt">100</strong>
<%= Resources.vsk.charsleft %>.
</div>
</div>
</fieldset>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info" data-dismiss="modal">Close</button>
<asp:Button ID="btn_send" class="btn btn-primary" runat="server" OnClick="btn_send_Click" />
</div>
</div>
</div>
The send button in the modal is what calls the server side method. I'm trying to completely get rid of this modal and have the function invoked just by clicking the link. Is there a way to do this?
Use Ajax on button click. follow link for basics of Ajax=
http://www.w3schools.com/jquery/ajax_ajax.asp

ListBox selections not getting updated on postback Asp.net

In my application I have a ListView that shows data with a few different columns. I want to give user flexibility to choose columns they want to see in the ListView. So in my page, I have added following
<div class="ibox-content">
<div id="modal-form" class="modal fade" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<div class="row">
<div class="col-sm-12 b-r">
<h3 class="m-t-none m-b">Choose Columns</h3>
<p>Move columns from Available to Selected List box to show in the list below</p>
<div class="form-group col-md-4">
<label class="control-label-custom" for="lblAvailableColumns">Available Columns</label>
<asp:ListBox class="form-control" Style="height: 150px;" ClientIDMode="Static" ID="lbAvailableColumns" runat="server" placeholder="AvailableColumns" SelectionMode="Multiple"></asp:ListBox>
</div>
<div style="margin-left: 20px; margin-right: 10px; margin-top: 45px; margin-bottom: 5px" class="form-group col-md-1">
<input type="button" class="btn btn-default" id="left" value="<" />
<input type="button" class="btn btn-default" style="margin-top: 10px;" id="right" value=">" />
</div>
<div class="form-group col-md-4">
<label class="control-label-custom" for="lblSelectedColumns">Selected Columns</label>
<asp:ListBox class="form-control" Style="height: 150px;" ID="lbSelectedColumns" runat="server" placeholder="SelectedColumns" SelectionMode="Multiple"></asp:ListBox>
</div>
<div style="text-align: left;" class="form-group col-md-8">
<asp:LinkButton ID="lnkBtnApplyChooseColumns" TabIndex="4" runat="server" CausesValidation="false" class="btn btn-success" OnClick="lnkBtnApplyChooseColumns_Click">
<i class="glyphicon glyphicon-ok icon-white"></i> Apply </asp:LinkButton>
</div>
</div>
</div>
</div>
</div>
</div>
And this is launched like this
<a data-toggle="modal" class="btn btn-primary" href="../#modal-form"><i class="glyphicon glyphicon-th"></i>Choose Columns</a>
It looks like this while running
Though when Apply button is pressed, I dont see updated selections in lbSelectedColumns list box in the codebehind file. What im doing wrong here?
P.S: I think since I am showing this choose columns as a modal dialog using href, that is what is causing the issue. Any solution to this??

Categories