I'm new to working with the AJAX UpdatePanel and I've tried searching for an answer to this question and haven't found a solution yet.
I have multiple controls in an UpdatePanel since I am hiding and showing panels based on different button clicks. Also inside the UpdatePanel is a FileUpload control. Everything works fine until I upload a file. After that, none of the controls, like buttons or radio button lists, or JQuery scripts, like a datepicker, fire in the UpdatePanel after the upload.
Here is the aspx code:
<%# Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Admin.aspx.cs" Inherits="Site.Admin" %>
<%# MasterType virtualPath="~/Site1.master"%>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.12.4.js"></script>
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script type="text/javascript" src="scripts/jquery-ui-timepicker-addon.js"></script>
<link rel="stylesheet" href="Content/jquery-ui-timepicker-addon.css">
<script type="text/javascript">
function pageLoad() {
$(function () {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args) {
$('.picker').datetimepicker();
}
});
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True"></asp:ScriptManager>
<asp:UpdatePanel ID="adminUpdatePanel" UpdateMode="Conditional" ChildrenAsTriggers="True" runat="server">
<ContentTemplate>
<div class="form-group">
<div class='input-group date' id='datetimepicker3'>
<asp:TextBox ID="tb_EndDate" class="form-control picker" runat="server"></asp:TextBox>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
<div class="form-group">
<asp:RadioButtonList ID="rbl_Active" runat="server" OnSelectedIndexChanged="rbl_Active_SelectedIndexChanged" RepeatDirection="Horizontal" CellPadding="4" CellSpacing="4" AutoPostBack="True">
<asp:ListItem>Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
</asp:RadioButtonList>
</div>
<div class="form-group">
<label>Upload Photo</label>
<asp:FileUpload ID="imageFileUpload" runat="server" />
<asp:Button class="btn btn-primary" ID="btn_UploadImg" runat="server" Text="Upload Image" OnClick="btn_UploadImg_Click" CausesValidation="False" />
<asp:Button ID="btn_CancelImg" OnClick="btn_CancelImg_Click" class="btn btn-primary" runat="server" Text="Change/Remove Image" CausesValidation="False" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
And the code behind relating to the file upload:
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager.GetCurrent(this).RegisterPostBackControl(this.btn_UploadImg);
}
protected void btn_UploadImg_Click(object sender, EventArgs e)
{
bool isUploaded = uploadImage(imageFileUpload);
if (isUploaded)
{
btn_CancelImg.Visible = true;
}
}
I'm not sure what I'm doing wrong. It worked fine when run from Visual Studio, but when pushed to the server it all fails
Instead of setting Visible to true/false, can you please try:
<asp:Panel ID="pnlToHide" runat="server" style="display:none">
When you have to show, you can use the following:
protected void btnShow_Click(object sender, EventArgs e)
{
pnlToHide.Attributes["style"] = "display: '';";
}
Also, you can try fullpostback/render by using:
<Triggers>
<asp:PostBackTrigger ControlID="btnFileUpload"/>
</Triggers>
Related
i would like to try bootstrap pop over using asp.net
ive already tried and search for the ways to do this
function pageLoad(sender, args) {
$('[data-toggle="popover"]').popover({
html: true,
placement: "bottom",
content: function () {
return $('#PopoverConditionMasterPart').html();
}
});
};
but still there's no clear sign for popover.
and in my debugger i see errors like $ is not defined and .popover is not a function
another problem is most of the tutorial is in MVC
can someone give me advise or better explanation to do this.
Thanks in advance and keep going!
here is my current work:
css:
<asp:Content ID="Content2" ContentPlaceHolderID="css" runat="server">
<link href="Content/bootstrap.css" rel="stylesheet" />
</asp:Content>
html:
<asp:Content ID="Content3" ContentPlaceHolderID="body" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div class="row">
<div class="col-md-2 col-lg-2">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label runat="server" data-toggle="popover" data-placement='bottom' title="sample" ID="lblConditionMasterPart" CssClass="form-control popover PopoverConditionMasterPart" Text="click me" Style="cursor: pointer;"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel9" runat="server">
<ContentTemplate>
<div id="PopoverConditionMasterPart" style="display: none;">
<button type= "button" title="bnt1" class="form-control btn btn-secondary"> btn1</button>
<button type= "button" title="bnt1" class="form-control btn btn-primary"> btn2</button>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</asp:Content>
script:
<asp:Content ID="Content4" ContentPlaceHolderID="script" runat="server">
<script src="Scripts/jquery-3.2.1.js" type="text/javascript"></script>
<script src="Scripts/bootstrap.js" type="text/javascript"></script>
<script type="text/javascript">
function pageLoad(sender, args) {
$('[data-toggle="popover"]').popover({
html: true,
placement: "bottom",
content: function () {
return $('#PopoverConditionMasterPart').html();
}
});
};
</script>
</asp:Content>
It appears you are defining a pageLoad function but never calling it. You could call it in ready, but why not just do what the function does on page load:
<script type="text/javascript">
$(document).ready(
$('[data-toggle="popover"]').popover({
html: true,
placement: "bottom",
content: function () {
return $('#PopoverConditionMasterPart').html();
}
});
});
</script>
I have created user control with label and image
i need raise event when click on the user control
when click on the div which contain the label and image
user control code is bellow
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="ImageButton.ascx.cs" Inherits="AdvancedGrid.UC.ImageButton" %>
<div id="divClickableDiv" runat="server">
<div>
<asp:Image ID="Button_Image" ImageUrl="" runat="server" />
</div>
<div>
<asp:Label ID="Button_Text" runat="server" Text="Button"></asp:Label>
</div>
</div>
why not use use ImageButton control instead of Image if that is what you need? Try something like this:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="ImageButton.ascx.cs" Inherits="AdvancedGrid.UC.ImageButton" %>
<div id="divClickableDiv" runat="server">
<div>
<asp:ImageButton ID="Button_Image" ImageUrl="" runat="server" OnClick="Button_Image_Click" />
</div>
<div>
<asp:Label ID="Button_Text" runat="server" Text="Button"></asp:Label>
</div>
</div>
- OnClick="Button_Image_Click" takes you to code behind where you can go to any URL you want like this:
protected void Button_Image_Click(object sender, EventArgs e)
{
Response.Redirect("~/page.aspx");
}
- or instead of OnClick and without code-behind try:
<asp:ImageButton ID="Button_Image" ImageUrl="" runat="server" OnClick="window.location.href = '<%= ResolveUrl("~/page.aspx") %>'" />
or
<asp:ImageButton ID="Button_Image" ImageUrl="" runat="server" OnClientClick="window.location.href='page.aspx'; return false;" />
I am newbie. I am working on asp.net website. I have added datepicker and it works fine. Now I want to get that date and compare it with date in my database. But I have no idea of how to do it. I also goggled but couldn't find any solution.
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="reserve" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script type="text/javascript">
$(document).ready(function () {
$('#coin-slider').coinslider();
});
</script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="jquery.datepick.js"></script>
<script type="text/javascript">
$(function () {
$('#popupDatepicker').datepick();
});
function showDate(date) {
alert('The date chosen is ' + date);
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<input type="text" id="popupDatepicker" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<div id='coin-slider' >
<a target="_blank"> </a>
<a>
<img id="Img2" src="~/Images/ar1.jpg" alt="header1" height="120" runat="server" style="width: 110px"/>
<img id="Img3" src="~/Images/ar2.jpg" alt="header1" height="120" runat="server" style="width: 110px"/>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</a>
</div>
</asp:Content>
Use DateTime.Compare(Date1, Date2) in code behind.
it'll give you differnce between the datetimes. Is this what you looking for
I am sorry I am repeating this question. Rather, I am having to repeat it. The last time I posted this, I dint get an answer. I have googled for more than 3 hrs, dint find an answer. Heres the html for the linkbutton and the modal popup. The link button is inside/on a tab panel and auto postback is set to true.
<asp:LinkButton ID="lnkAddNewAddress" runat="server" OnClick="lnkAddNewAddress_Click">Click Here To Add New Address</asp:LinkButton>
<asp:ModalPopupExtender ID="lnkAddNewAddress_ModalPopupExtender" runat="server" BackgroundCssClass="modalBackground"
DynamicServicePath="" Enabled="True" PopupControlID="pnlMyAddressBook" TargetControlID="lnkAddNewAddress"
ViewStateMode="Enabled" >
</asp:ModalPopupExtender>
I want the clickevent of the linkbutton to fire which is not happening. However clicking on the link does open the modal popup extender (which is also something I want)... How do I get into the click event. I know that a postback is being avoided here because of the modal popup probably...but I dont the solution for it....
The code on save button:
if(hdnfld.Value.ToString()!=null)
{
if(hdnfld.Value.ToString()=="Save")
{
SaveNewAddress();
}
else
{
UpdateAddress();
}
<%# Page StylesheetTheme="" Title="" Language="C#" MasterPageFile="~/Site.Master"
AutoEventWireup="true" CodeBehind="frmMyAccountMyProfile.aspx.cs" Inherits="WebApplication1.frmMyAccountMyProfile" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<script type="text/javascript">
function CheckType(type)
{
document.getElementById("hdnfld").value = type;
alert(document.getElementById("hdnfld").value);
return false;
}
</script>
<link href="Styles/myStyleSheet.css" rel="stylesheet" type="text/css" />
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div class="divwrap">
<table style="width: 100%; margin-right: 0px;">
<tr>.........
<td>
<asp:LinkButton ID="lnkAddNewAddress" runat="server" OnClientClick="return CheckType('Save');">Click Here To Add New Address</asp:LinkButton>
<asp:HiddenField ID="hdnfld" runat="server" />
<asp:ModalPopupExtender ID="lnkAddNewAddress_ModalPopupExtender" runat="server" BackgroundCssClass="modalBackground" DynamicServicePath="" Enabled="True" PopupControlID="pnlMyAddressBook" TargetControlID="lnkAddNewAddress"
ViewStateMode="Enabled">
</asp:ModalPopupExtender>
...........
<asp:Button ID="btnEdit" runat="server" CssClass="roundcorner btn" OnClick="btnEdit_Click" OnClientClick="return CheckType('Edit');" Text="Edit" />
<asp:Panel ID="pnlMyAddressBook" runat="server" BackColor="White" CssClass="roundcorner">
you can use hidden field instead of viewstate, if you really want to retain some value at code behind. You can access hidden field at client side as well as in code behind too.
<asp:LinkButton ID="lnkAddNewAddress" runat="server" OnClientClick="return CheckType('save');">Click Here To Add New Address</asp:LinkButton>
<asp:HiddenField ID="hdf_type" runat="server" />
Javascript code
function CheckType(type) {
document.getElementById("hdf_type").value = type;
return false;
}
Access value in code behind when clicked on save button, and perform your action save or update according to value in hidden field.
hdf_type.Value.ToString();
MORE HELP FOR YOU
HTML FILE SHOULD LOOK LIKE THIS
below i'm posting the whole code which is working fine for me.
<head runat="server">
<title></title>
<script type="text/javascript">
function CheckType(type) {
document.getElementById("hdf_type").value = type;
alert(document.getElementById("hdf_type").value);
return false;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:LinkButton ID="lnkAddNewAddress" runat="server" OnClientClick="return CheckType('save');">Click Here To Add New Address</asp:LinkButton>
<asp:Button ID="btn" runat="server" OnClientClick="return CheckType('edit');" Text="Click Here To Add New Address" />
<asp:ModalPopupExtender ID="lnkAddNewAddress_ModalPopupExtender" runat="server" BackgroundCssClass="modalBackground"
DynamicServicePath="" Enabled="True" PopupControlID="pnlMyAddressBook" TargetControlID="lnkAddNewAddress"
ViewStateMode="Enabled">
</asp:ModalPopupExtender>
<div id="pnlMyAddressBook" style="height: 100px; width: 100px; display: none; background-color: Gray">
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /><br />
</div>
<asp:HiddenField ID="hdf_type" runat="server" />
</div>
</form>
getting value at code behind:
Try this:
<asp:LinkButton ID="lnkAddNewAddress" runat="server" OnClick="lnkAddNewAddress_Click">Click Here To Add New Address</asp:LinkButton>
<asp:ModalPopupExtender ID="lnkAddNewAddress_ModalPopupExtender" runat="server" BackgroundCssClass="modalBackground"
DynamicServicePath="" Enabled="True" PopupControlID="pnlMyAddressBook" TargetControlID="btnHidden">
</asp:ModalPopupExtender>
<asp:Button ID="btnHidden" runat="server" style="Display:none;" Text="Button"/>
In Code behind:
protected void lnkAddNewAddress_Click(object sender, EventArgs e)
{
lnkAddNewAddress_ModalPopupExtender.Show();
}
The problem happens on this page. When you press Button 1 a table is displayed on the page. Pressing Button 2 does nothing at all (empty function), but for some reason the button ends up out of the div it is in.
I use twitter bootstrap CSSs (latest version - 2.2.1)
Here's the markup:
<%# Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.master" CodeBehind="Test.aspx.cs" Inherits="CalendarImporterWeb.WebForm1" %>
<%# Register TagPrefix="uc" TagName="Timetable" Src="~/TimetableControl.ascx" %>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManagerMain" runat="server" />
<script language="javascript" type="text/javascript">
<!--
function popupWindow(url) {
newwindow = window.open(url, 'name', 'height=520,width=500');
if (window.focus) { newwindow.focus() }
return false;
}
function showControl(controlID) {
var control = document.getElementById(controlID);
control.style.display = "block";
control.style.visibility = "visible";
}
function hideControl(controlID) {
var control = document.getElementById(controlID);
control.style.display = "none";
}
// -->
</script>
<table border="0" width=500>
<tr height="50">
<td colspan="2" align="left">
<asp:Button runat="server" id="btnGetCourses" text="Button 1" CssClass="btn btn-info"
OnClientClick="showControl('ImageSpinner');" onclick="btnGetCourses_Click" />
</td></tr>
</table>
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" updatemode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnGetCourses" EventName="Click" />
</Triggers>
<ContentTemplate>
<uc:Timetable id="Timetable1" runat="Server" Visible="false"></uc:Timetable>
</ContentTemplate>
</asp:UpdatePanel>
<div class="jumbotron">
<asp:button id="btnStart" class="btn btn-primary" runat="Server"
Text="Button 2" onclick="btnStart_Click" />
<br /><br />
</div>
</form>
</asp:Content>
And the cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CalendarImporterWeb
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnGetCourses_Click(object sender, EventArgs e)
{
Timetable1.LoadCourses("","","");
}
protected void btnStart_Click(object sender, EventArgs e)
{
}
}
}
It looks like you have an extraneous "-->" in your markup somewhere - I see it on the rendered page at the top right.
Found the problem:
The TimetableControl had a spare /div in its code. Since it was not visible (ASP.NET Visible property, not HTML visible property) it didn't matter until it was made visible
Thanks for the help