Asp.Net UpdatePanel not working properly on mobile browsers
I have a checkbox and a dropdownlist (Disabled at first) in an UpdatePanel. If the checkbox is checked, then the dropdownlist become enabled.
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel" runat="server">
<ContentTemplate>
<asp:CheckBox ID="CheckBox" OnCheckedChanged="CheckBox_CheckedChanged" runat="server" />
<asp:DropDownList ID="DropDownList" Enabled="false" runat="server"></asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
C# Code Behind:
protected void CheckBox_CheckedChanged(object sender, EventArgs e)
{
if (DropDownList.Enabled)
DropDownList.Enabled = false;
else
DropDownList.Enabled = true;
}
On Desktop browsers (Such as Chrome) it works fine. On the other hand, on a mobile browser (in this case Safari on IOS) when the checkbox is checked, nothing happens. I believe it is related to the UpdatePanel, but I'm not sure why on desktop browser it work's fine, and on Safari in IOS it won't work properly.
See also questions close to this topic
-
getting prob on reading nested class c#
Hi really need assistance here,
I have 2 classes which i use to read from json i need to save into 2 tables (root and participants) in 1 submission. i will have only 1 root with 1 or many participants. i have no prob saving the root but i have prob reading if i am sending both (root with participants}
[ { "NoIC": "122233243", "Nama": "TEST NAME", ... "Participant": [ { "Nama" : "Participant 1", "Bil" : "1", ... }, { "Nama" : "Participant 2", "Bil" : "1", .... } ] } ] public class Participant { public string ref_no { get; set; } public string Nama { get; set; } public string Bil { get; set; } public string Price { get; set; } public string RequestedPlace { get; set; } public string RequestedExe { get; set; } public string RequestedDate { get; set; } public string Type { get; set; } } public class Root { public string NoIC { get; set; } public string Nama { get; set; } public string HPNo { get; set; } public string Email { get; set; } public string Type { get; set; } public string RegisterBy { get; set; } public List<Participant> Participant { get; set; } } public string RegisterApplication([FromBody] Root register, Participant participants) { try { using (MySqlConnection sql = new MySqlConnection(_connectionString)) { using (MySqlCommand cmd = new MySqlCommand("GetInsertApplication", sql)) { sql.Open(); cmd.CommandType = System.Data.CommandType.StoredProcedure; // cmd.Parameters.AddWithValue("@refNo", register.RefNo); cmd.Parameters.AddWithValue("@NoIC", register.NoIC); cmd.Parameters.AddWithValue("@Nama", register.Nama.ToUpper()); cmd.Parameters.AddWithValue("@NoFonHp", register.HPNo); cmd.Parameters.AddWithValue("@Email", register.Email); cmd.Parameters.AddWithValue("@refType", register.Type); cmd.Parameters.AddWithValue("@RegisterBy", register.RegisterBy); ...... ref_no = refnoParameter.Value.ToString(); //will pass this refno to child/participant
my prob is here. i need to read the child (1 Root can have more than 1 participant)
List<Participant> participants = new List<Participant>(); using (MySqlCommand cmd2 = new MySqlCommand("GetInsertParticipant", sql)) { cmd2.Parameters.AddWithValue("@ref_no", ref_no); cmd2.Parameters.AddWithValue("@Nama", participant.Nama.ToUpper()); cmd2.Parameters.AddWithValue("@Bil", participant.Bil); cmd2.Parameters.AddWithValue("@Price", participant.Price); cmd2.Parameters.AddWithValue("@RequestedPlace", participant.RequestedPlace); cmd2.Parameters.AddWithValue("@RequestedExe", participant.RequestedExe); cmd2.Parameters.AddWithValue("@RequestedDate", participant.RequestedDate); cmd2.Parameters.AddWithValue("@Type", participant.Type); cmd2.Connection.Open(); cmd2.CommandType = CommandType.Text; cmd2.ExecuteNonQuery();
}}}}}
anybody please, i stuck here for few days and i really need your help/opinion. thaks in advanced
-
How do I insert input from form to database?
My model looks like this:
public class Customer { public int CustomerId { get; set; } [Required(ErrorMessage = "Please enter a valid first name")] public string FirstName { get; set; } [Required(ErrorMessage = "Please enter a valid last name")] public string LastName { get; set; } [Required(ErrorMessage = "Please enter a valid address")] public string Address { get; set; } public string Email { get; set; } [Required(ErrorMessage = "Please enter a valid city")] public string City { get; set; } public string Phone { get; set; } [Range(1, 5, ErrorMessage = "Please enter a valid country")] public int CountryId { get; set; } public Country Country { get; set; } [Required(ErrorMessage = "Please enter a valid state")] public string State { get; set; } [Required(ErrorMessage = "Please enter a valid postal code")] public string PostalCode { get; set; } public string fullname => FirstName + LastName; }
My controller looks like this:
public class CustomerController : Controller { private CustomerContext context { get; set; } public CustomerController(CustomerContext ctx) { context = ctx; } public IActionResult List() { var customers = context.Customers.ToList(); return View(customers); } [HttpGet] public IActionResult Add() { ViewBag.Action = "Add"; ViewBag.Countries = context.Countries.OrderBy(c => c.Name).ToList(); return View("Edit", new Customer()); } [HttpGet] public IActionResult Edit(int id) { ViewBag.Action = "Edit"; ViewBag.Countries = context.Countries.OrderBy(c => c.Name).ToList(); var customer = context.Customers .Include(c => c.Country) .FirstOrDefault(c => c.CustomerId == id); return View(customer); } [HttpPost] public IActionResult Edit(Customer customer) { string action = (customer.CustomerId == 0) ? "Add" : "Edit"; if (ModelState.IsValid) { if (action == "Add") { context.Customers.Add(customer); } else { context.Customers.Update(customer); } context.SaveChanges(); return RedirectToAction("List", "Customer"); } else { ViewBag.Action = action; ViewBag.Countries = context.Countries.OrderBy(c => c.Name).ToList(); return View(customer); } }
I also have a DbContext file with data i created to test other things:
public class CustomerContext : DbContext { public CustomerContext(DbContextOptions<CustomerContext> options) :base(options) { } public DbSet<Customer> Customers { get; set; } public DbSet<Country> Countries { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Country>().HasData( new Country { CountryId = 1, Name = "Canada"}, new Country { CountryId = 2, Name = "United States"}, new Country { CountryId = 3, Name = "United Kingdom" }, new Country { CountryId = 4, Name = "Mexico" }, new Country { CountryId = 5, Name = "Russia" } ); modelBuilder.Entity<Customer>().HasData( new Customer { CustomerId = 1, FirstName = "Bruce", LastName = "Wayne", Phone = "416-123-4567", Email = "bruce.wayne@gmail.com", CountryId = 1, Address = "123 sesame street", City = "Toronto", PostalCode = "L812A", State = "Ontario" } ); }
I already did the add-migration and updated my database via the package manager console. I created a form in the view that looks like this:
Cancel<form method="post" asp-action="Add"> <div asp-validation-summary="All"> <div> <label asp-for="FirstName">First Name</label> <input type="text" name="FirstName" asp-for="FirstName" /> </div> <div> <label asp-for="LastName">Last Name</label> <input type="text" name="LastName" asp-for="LastName" /> </div> <div> <label asp-for="Address">Address</label> <input type="text" name="Address" asp-for="Address" /> </div> <div> <label asp-for="City">City</label> <input type="text" name="City" asp-for="City" /> </div> <div> <label asp-for="State">State</label> <input type="text" name="State" asp-for="State" /> </div> <div> <label asp-for="PostalCode">Postal Code</label> <input type="text" name="Postal Code" asp-for="PostalCode" /> </div> <div> <label asp-for="CountryId">Country</label> <select name="Country" asp-for="CountryId"> @foreach (Country country in ViewBag.Countries) { <option value="@country.CountryId">@country.Name</option> } </select> </div> <div> <label asp-for="Email">Email</label> <input type="text" name="Email" asp-for="Email" /> </div> <div> <label asp-for="Phone">Phone</label> <input type="text" name="Phone" asp-for="Phone" /> </div> <input type="hidden" asp-for="CustomerId" /> </div> <button type="submit" value="Save" asp-controller="Customer" asp-action="List">Save</button>
I've tried looking up multiple different solutions to solve my issue but I cant seem to figure out how to solve it. If someone could help me that would be much appreciated. thanks in advance.
-
Submit button doenst work with script asp.net mvc5
I have a maybe simple problem but I don`t have that much experience with scripts:
I have this Skript in my _Layout.cshtml:
<script> $('button').click(function () { $(this).prop('disabled', true); }); </script>
and one of my views:
@using (Html.BeginForm("Create", "Home", FormMethod.Post, null)) { @Html.AntiForgeryToken() <div class="mt-5 d-flex flex-row"> <textarea class="form-control" name="TextArea"></textarea> <button class="btn btn-secondary btn-block mt-2 post-btn" type="submit" id="PostButton">Post</button> </div> }
This form works great without the script, but for any reason with the script it doesn`t work.
I placed the script in the _layout.cshtml because I want to have it for all buttons in my asp.net page.
After click on the button the button is disabled - as I wish - but the action result "Create" in the HomeController will not called.
I think I need to extend the script but can someone help me how to do it?
Thanks all
-
how to make a string of strings in this API (Flutter API)
Future<Null> getData() async { final SharedPreferences prefs = await _sprefs; int data = prefs.getInt('id'); String dToken = prefs.getString('token'); String dDay = "SENIN";
dDay : "SUNDAY","MONDAY",
-
problem in adding network image to flutter
i am creating a flutter wallpaper app i am facing issues in making a list with some categories. images are not loading and it is showing this error [ : package:flutter/src/_newtwork_image_io.dart': failed assertion : line 25 pos 14 : 'url != null' : is not true. see also https://flutter.dev/docs/testing/errors ]
can any help i in this here is my code for the app this is my main.dart :===
// this is my main.dart : import 'package:flutter/material.dart'; import 'package:wallpaperdex/views/home.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'WallpaperDex', debugShowCheckedModeBanner: false, theme: ThemeData( primaryColor: Colors.white, ), home: Home(), ); } }
this is my home.dart where i am creating my list
import 'package:flutter/material.dart'; import 'package:wallpaperdex/data/data.dart'; import 'package:wallpaperdex/model/categorie_model.dart'; import 'package:wallpaperdex/widgets/widget.dart'; class Home extends StatefulWidget { @override _HomeState createState() => _HomeState(); } class _HomeState extends State<Home> { // List<CategorieModel> categories = new List(); @override void initState() { categories = getCategories(); super.initState(); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, appBar: AppBar( title: BrandName(), elevation: 0.0, ), body: Container( child: Column( children: <Widget>[ Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(36), color: Color(0xfff5f8fd), ), margin: EdgeInsets.symmetric(horizontal: 24), padding: EdgeInsets.symmetric(horizontal: 20), child: Row( children: <Widget>[ Expanded( child: TextField( decoration: InputDecoration( hintText: "Search", border: InputBorder.none), ), ), Icon(Icons.search), ], ), ), SizedBox( height: 16, ), Container( height: 80, child: ListView.builder( // padding: , itemCount: categories.length, shrinkWrap: true, scrollDirection: Axis.horizontal, itemBuilder: (context, index) { return CategoriesTile(categories[index].categorieName, categories[index].imgUrl); }, ), ) ], ), ), ); } } class CategoriesTile extends StatelessWidget { final String imgUrl, title; CategoriesTile(this.title, this.imgUrl); @override Widget build(BuildContext context) { return Container( child: Stack( children: <Widget>[ Container( child: Image.network(imgUrl), ), Container( child: Text(title), ), ], ), ); } }
this is my data.dart:
import 'package:wallpaperdex/model/categorie_model.dart'; List<CategorieModel> getCategories() { List<CategorieModel> categories = new List(); CategorieModel categorieModel = new CategorieModel(); categorieModel.imgUrl = "https://images.pexels.com/photos/545008/pexels-photo-545008.jpeg?auto=compress&cs=tinysrgb&dpr=2&w=500"; categorieModel.categorieName = "Street Art"; categories.add(categorieModel); categorieModel = new CategorieModel(); // categorieModel.imgUrl = "https://images.pexels.com/photos/704320/pexels-photo-704320.jpeg?auto=compress&cs=tinysrgb&dpr=2&w=500"; categorieModel.categorieName = "Wild Life"; categories.add(categorieModel); categorieModel = new CategorieModel(); // categorieModel.imgUrl = "https://images.pexels.com/photos/34950/pexels-photo.jpg?auto=compress&cs=tinysrgb&dpr=2&w=500"; categorieModel.categorieName = "Nature"; categories.add(categorieModel); categorieModel = new CategorieModel(); // categorieModel.imgUrl = "https://images.pexels.com/photos/466685/pexels-photo-466685.jpeg?auto=compress&cs=tinysrgb&dpr=2&w=500"; categorieModel.categorieName = "City"; categories.add(categorieModel); categorieModel = new CategorieModel(); // categorieModel.imgUrl = "https://images.pexels.com/photos/1434819/pexels-photo-1434819.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260"; categorieModel.categorieName = "Motivation"; categories.add(categorieModel); categorieModel = new CategorieModel(); // categorieModel.imgUrl = "https://images.pexels.com/photos/2116475/pexels-photo-2116475.jpeg?auto=compress&cs=tinysrgb&dpr=2&w=500"; categorieModel.categorieName = "Bikes"; categories.add(categorieModel); categorieModel = new CategorieModel(); // categorieModel.imgUrl = "https://images.pexels.com/photos/1149137/pexels-photo-1149137.jpeg?auto=compress&cs=tinysrgb&dpr=2&w=500"; categorieModel.categorieName = "Cars"; categories.add(categorieModel); categorieModel = new CategorieModel(); return categories; }
this is my widget.dart :
import 'package:flutter/material.dart'; // ignore: non_constant_identifier_names Widget BrandName() { return Row( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text( "Wallpaper", style: TextStyle(color: Colors.black87), ), Text( "Dex", style: TextStyle(color: Colors.blue), ) ], ); }
this is my category_model.dart
class CategorieModel { String categorieName; String imgUrl; }
this is all , here is screenshot of error enter image description here
-
How can I get access token from app Line in react-native?
I have a project expo, feature is login with app Line. I have research it but expo only support Google, Facebook... Do you guy have solution with it let me know. Tks you all.
-
Trigger UpdateProgress by clicking on link button of gridview in ASP NET C#
I have add a
LinkButton
inGridView
<asp:TemplateField HeaderText="Nr." ItemStyle-HorizontalAlign="Center" ItemStyle-CssClass="ddl_Class_new"> <ItemTemplate> <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1"> <ProgressTemplate> <div class="modal"> <div class="center"> <img alt="" src="/aspnet/Img/831.gif" /> </div> </div> </ProgressTemplate> </asp:UpdateProgress> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <Triggers> <asp:AsyncPostBackTrigger ControlID="Link" /> </Triggers> <ContentTemplate> <asp:LinkButton ID="Link" runat="server" Text="download"></asp:LinkButton> </ContentTemplate> </asp:UpdatePanel> </ItemTemplate> </asp:TemplateField>
On the
rowdatabound
I set onLinkButton
the propertyPostBackUrl
that will navigate to the next form in the website for export xls fileprotected void gv_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { LinkButton Link = (LinkButton)e.Row.FindControl("Link"); string ese = DataBinder.Eval(e.Row.DataItem, "ese").ToString(); if (!String.IsNullOrEmpty(ddl.SelectedValue)) { Link.PostBackUrl = "xls.aspx?e=" + ese.ToString() + "&a=" + ddl.SelectedValue; } else { Link.PostBackUrl = "xls.aspx?e=" + ese.ToString(); } } }
I have set also a
UpdateProgress
in myUpdatePanel
.However so when I click on those link button, don't show my loading screen...
Please help me...
-
C# ASP.NET - Not able to hide image in updateprogress after response redirect
I have one Ajax UpdateProgress for only one UpdatePanels in the page.
The updatepanel has a gridview with a download button.
Once user clicks on the button, the 'wait' Image shows up, but keeps showing even after the download is complete.
How should I hide it, once the download is done.
My code below but not working, because the image is showing even after the download is complete.
.cs
protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { ImageButton ImageButton1 = (ImageButton)sender; sIDint = ImageButton1.CommandArgument.ToString(); Thread.Sleep(3000); HttpCookie cookie = new HttpCookie("ExcelDownloadFlag") { Value = "Flag", Expires = DateTime.Now.AddDays(1) }; Response.AppendCookie(cookie); Response.Redirect("pdf.aspx?sID=" + sIDint.ToString()); ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "HideImage();", true); ImageButton imgLike = (ImageButton)FindControl("imgLike"); if (imgLike != null) { imgLike.Visible = false; } }
.aspx
function HideImage() { $(#imgLike).hide(); } <asp:TemplateField HeaderText="Dwn"> <ItemTemplate> <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1"> <ProgressTemplate> <div class="modal"> <div class="center"> <img alt="" src="/Img/ajax-loader.gif" id="imgLike" /> </div> </div> </ProgressTemplate> </asp:UpdateProgress> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <Triggers> <asp:AsyncPostBackTrigger ControlID="ImageButton1" /> </Triggers> <ContentTemplate> <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="/img/download.gif" OnClick="ImageButton1_Click" CommandArgument='<%# Eval("ID") %>' /> </ContentTemplate> </asp:UpdatePanel> </ItemTemplate> </asp:TemplateField>
Edit
Solved using
protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { ImageButton ImageButton1 = (ImageButton)sender; string sIDint = ImageButton1.CommandArgument.ToString(); Thread.Sleep(3000); HttpCookie cookie = new HttpCookie("ExcelDownloadFlag") { Value = "Flag", Expires = DateTime.Now.AddDays(1) }; Response.AppendCookie(cookie); ScriptManager.RegisterStartupScript(this, typeof(string), "OpenWindow", "window.open('pdf.aspx?sID=" + sIDint + "');", true); }
-
LinkButton not working on Postback within UpdatePanel
ASP Net form using C# for code-behind
I have a linkButton inside an UpdatePanel which on page load works.
I click another control on the page which causes Postback and clicking the same linkButton stops firing.
I have removed a lot of the CSS and other bits of programming to make this a little clearer.
Here is the linkbutton
<asp:UpdatePanel ID="UpdatePanel1" runat="server" OnPreRender="UpdatePanel_PreRender"> <Triggers> <asp:AsyncPostBackTrigger ControlID="completebtn" EventName="Click"/> </Triggers> <ContentTemplate> <asp:LinkButton id="completebutton" runat="server" class="btn w-100 blue-border-button" >Mark as Completed</asp:LinkButton> ..... .....
And the query that fires
<script type="text/javascript"> $(document).ready(function() { $('#<%= completebutton.ClientID %>').click(function () { //event.preventDefault(); <%-- __doPostBack('#<%= completebtn.ClientID %>', '');--%> alert('Hello'); }); });
So on page load, first time i click the button, i see the alert Hello, i change a control on the same page i.e. dropdown, radioButton which does a Postback and then click the same completeButton again and nothing happens.
I have seen the below code to add to the page load event
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "dosomething();", true);
but im not sure what code i need to register here as its the click event of a linkButton or even if this is the correct procedure? Could anyone point me in the right direction.