i have used ajax sliderextender for the slider provision...im using vs2005.. if i write the below mentioned code then the slider is not shown inthe output page.. where im going wrong.. any help..pls...
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</ajaxToolkit:ToolkitScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="Slider2" runat="server" Text="0" AutoPostBack="true"></asp:TextBox><br />
<asp:TextBox ID="Slider2_BoundControl" Width="30" runat="server" Visible="true" Text="0"></asp:TextBox><br />
<ajaxToolkit:SliderExtender ID="SliderExtender2" runat="server" BehaviorID="Slider2"
TargetControlID="Slider2" BoundControlID="Slider2_BoundControl" Orientation="Horizontal"
Minimum="-15" Maximum="30" Steps="45" EnableHandleAnimation="true" TooltipText="Select Bar Weight"
RaiseChangeOnlyOnMouseUp="true">
</ajaxToolkit:SliderExtender>
</ContentTemplate>
</asp:UpdatePanel>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ToolkitScriptManager1.RegisterAsyncPostBackControl(Slider2)
End Sub
Related
I have created a basic User Control with three drop down (Year,Month,Date) that exposes properties that
I wish to set from my code-behind page. This works fine
<%# Control Language="VB" AutoEventWireup="false" CodeFile="DateControl.ascx.vb" ClassName="DateControl"
Inherits="DateControl" %>
<%--<asp:ScriptManager ID="dd" runat="server">
</asp:ScriptManager>--%>
<div class="form-inline">
<div class="form-group">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="ddlDay" OnSelectedIndexChanged="DDLActual_OnChange" runat="server" CssClass="form-control" />
<asp:DropDownList ID="ddlMonth" OnSelectedIndexChanged="DDLActual_OnChange" runat="server" CssClass="form-control" />
<asp:DropDownList ID="ddlYear" OnSelectedIndexChanged="DDLActual_OnChange" runat="server" CssClass="form-control" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
The problem started when i placed this usercontorl in repeater and try to access from codebehind on every item change by creating
method
<uc3:DateControl ID="txtDate" runat="server" Visible="false" OnChange="txtDate_PostBack" />
Protected Sub txtDate_PostBack(ByVal sender As Object, ByVal e As System.EventArgs)
Dim btndetails As DateControl = TryCast(sender, DateControl)
Dim ltrIsFormulaApplied As Literal = DirectCast(btndetails.FindControl("ltrIsFormulaApplied"), Literal)
End If
btndetails is showing nothing, i am not able to access values of other control, any help would be really appreciated..
Working with asp.net, I have a gridview inside an update panel, populated with dynamic user controls (loaded in placeholder1 on rowdatabound). A user enters text in a textbox of the user control, clicks the "confirm" button of the user control, a modal popup displays a "confirmation" message with the user's value of the text box. The button click event of the user control handles setting the modal popup extender control values and shows the popup.
This works as expected when the gridview is not in an update panel/no update panel is used. Once I place the gridview in an update panel, when the modal popup appears, it doesn't show the values that were set in the button click event (I've confirmed the click event is firing, controls are being found, and values are getting set in the event). I must be missing something...and/or don't quite understand the architecture of the update panel and how it behaves with dynamic controls.
[code below has been simplified]
GRIDVIEW
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="gvSaleData" runat="server" DataKeyNames="ItemNumber"
AutoGenerateColumns="False" ShowFooter="True" />
<Columns>
<asp:TemplateField ShowHeader="false">
<ItemTemplate>
<div>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
MODAL POPUP
<asp:modalpopupextender id="mp1" runat="server"
cancelcontrolid="btnCancel"
targetcontrolid="btnShow" popupcontrolid="pnlShow"
popupdraghandlecontrolid="PopupHeader" drag="true"
backgroundcssclass="ModalPopupBG">
</asp:modalpopupextender>
<asp:panel id="pnlShow" style="display:none" runat="server">
<div class="popupcontainer">
<div>Your Value: <asp:Label ID="lblUserValue" runat="server" Text=""></asp:Label></div>
<asp:Button ID="btnConfirm" runat="server" Text="Confirm"
onclick="btnConfirm_Click" CssClass="submit"/>
<asp:Button ID="btnCancel" runat="server" Text="Return"
onclick="btnCancel_Click" CssClass="submit"/>
</div>
</asp:panel>
USER CONTROL CODE BEHIND
protected void btnShowConfirmation_Click(object sender, EventArgs e)
{
AjaxControlToolkit.ModalPopupExtender mp =(AjaxControlToolkit.ModalPopupExtender)Page.FindControl("mp1");
Label lblUserValue = (Label)mp.FindControl("lblUserValue");
lblUserValue.Text = textbox1.Text;
mp.Show();
}
I only came across this question recently, a year after it was asked and am posting a solution in case any one else has the same problem.
The answer is to put the the ModalPopupExtender panel "pnlShow" inside an update panel with an AsycPostBackTrigger added whose ID is btnShowConfirmation.
If btnShowConfirmation is dynamically added it should be added to the UpdatePanel dynamically.
The attached example shows two buttons which raise the modal popup. The trigger reference to btnX is added in the aspx code,the btnY triger is added dynamically as an example.
[Aspx code]
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="TestModalPopup.aspx.vb"
Inherits="USSGAinfo.TestModalPopup" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.modalPopupX
{
background-color: #DDFFDD;
border-width: 2px;
border-style: solid;
border-color: black;
padding-top: 20px;
padding-left: 10px;
width: 400px;
height: 150px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</ajaxToolkit:ToolkitScriptManager>
<!-- Hidden Field -->
<asp:UpdatePanel runat="server" ID="up1" ChildrenAsTriggers="false" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="OkButton" />
</Triggers>
<ContentTemplate>
<asp:Button runat="server" ID="btnX" Text="X" />
<asp:Button runat="server" ID="btnY" Text="Y" /><br />
<asp:Label runat="server">Confirm:</asp:Label><asp:Label runat="server" ID="lblResult"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:HiddenField ID="hidForModal" runat="server" />
<ajaxToolkit:ModalPopupExtender ID="MPE" runat="server" TargetControlID="hidForModal"
PopupControlID="pnlTarget" BackgroundCssClass="modalBackground" PopupDragHandleControlID="pnlTarget">
</ajaxToolkit:ModalPopupExtender>
<asp:Panel ID="pnlTarget" Style="display: none" runat="server">
<asp:UpdatePanel runat="server" ID="up2" ChildrenAsTriggers="false" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnX" />
<%-- <asp:AsyncPostBackTrigger ControlID="btnY" />--%>
</Triggers>
<ContentTemplate> <asp:Panel runat="server" ID="Panel1" HorizontalAlign="Center" DefaultButton="OkButton"
CssClass="modalPopupX">
<asp:Table runat="server">
<asp:TableRow runat="server">
<asp:TableCell runat="server" ID="tcResult" HorizontalAlign="Center" Width="400px" Height="20px" BackColor="AntiqueWhite">Button Clicked:
<asp:label runat="server" ID="lblMPEResult"></asp:label>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<br />
<asp:Button ID="OkButton" runat="server" Text="Yes" />
<asp:Button ID="CancelButton" runat="server" Text="No" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
</form>
</body>
</html>
[Code behind]
Public Class TestModalPopup
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' Add btnY as trigger for ModalPopoup update panel
Dim trigger As New AsyncPostBackTrigger
trigger.ControlID = "btnY"
trigger.EventName = "Click"
up2.Triggers.Add(trigger)
End Sub
Private Sub btnX_Click(sender As Object, e As System.EventArgs) Handles btnX.Click
' Put button dependent info into ModalPopup and then show
lblMPEResult.Text = "XXX"
MPE.Show()
End Sub
Private Sub btnY_Click(sender As Object, e As System.EventArgs) Handles btnY.Click
' Put button dependent info into ModalPopup and then show
lblMPEResult.Text = "YYY"
MPE.Show()
End Sub
Private Sub OkButton_Click(sender As Object, e As System.EventArgs) Handles OkButton.Click
' Show that OK button was pressed and also information derived from the ModalPopup
lblResult.Text = lblMPEResult.Text
MPE.Hide()
End Sub
Private Sub CancelButton_Click(sender As Object, e As System.EventArgs) Handles CancelButton.Click
MPE.Hide()
End Sub
End Class
I created an asp.net web application (VB) with a dropdownlist that have lists of url to pages on the server. I am new to asp and VB. I have research different forums for solution and decided to ask for a specific solution to my problem.
Break down.
- I have a fully built page
- this page gets archive every two hrs to an archive folder(using a vbs)
- An XML file is generated with the file name and url (using a VBS)
- XMl is the datasource for the DDL.
What I want to accomplish is, when the user click an item from the DDL, they should be directed to that page.
After follow some of the suggestion from other forum and this one, nothing seems to work.
Once we dive into this, we will get some better understanding of any confusion.
The code-behind is VB, so i will prefered that language.
ASPX Page
enter code here
<%# Page Title="Home" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false"CodeBehind="Default.aspx.vb" Inherits="Status._Default" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"></asp:Content><asp:Content ID="BodyContent"runat="server" ContentPlaceHolderID="MainContent"></asp:Content>
<asp:XmlDataSource ID="statsXML"
runat="server" DataFile="~/Archive/Stats.xml"
XPath="Elements/Element" />
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="statsXML"
DataTextField="Name"
DataValueField="Value"
AutoPostBack="True"
CssClass="rightCol" />
<br />
<p>
<asp:Table ID="Table1" runat="server" GridLines="Horizontal" Width="100%">
<asp:TableRow BorderWidth="1" BorderStyle="Solid" Font-Size="12">
<asp:TableCell HorizontalAlign="Center" Text="Text here" BorderStyle="Solid" BorderWidth="0"
ForeColor="White" BackColor="#006699"></asp:TableCell>
</asp:TableRow>
<asp:TableRow BorderWidth="1" BorderStyle="Solid" Font-Size="12">
<asp:TableCell HorizontalAlign="Center" Text="Text here" BorderStyle="Solid"
BorderWidth="0" ForeColor="White" BackColor="#006699"></asp:TableCell>
</asp:TableRow>
</asp:Table>
<br />
</p>
<asp:Table ID="Table2" runat="server" GridLines="both" Width="100%" BorderColor="Black">
<asp:TableRow BorderWidth="1" BorderStyle="Solid" Font-Size="12" BorderColor="Black">
<asp:TableCell Width="50%" HorizontalAlign="Center" Text="Enviroment" BorderStyle="Solid" BorderWidth="1"
ForeColor="White" BackColor="#006699" BorderColor="Black"></asp:TableCell>
<asp:TableCell Width="50%" HorizontalAlign="Center" Text="State" BorderStyle="Solid"
BorderWidth="1" ForeColor="White" BackColor="#006699" BorderColor="Black"></asp:TableCell>
</asp:TableRow>
</asp:Table>`
Code-Behind
Public Class webform
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'If Not Page.IsPostBack Then
'End If
'If Page.IsPostBack Then
' ' Response.Redirect(Me.DropDownList1.SelectedValue)
' End If
End Sub
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Response.Redirect(DropDownList1.SelectedItem.Value)
End Sub
End Class
What you'll want to do is to first set AutoPostback to True on your DropDownList.
<asp:DropDownList ID="myDropDownlist" runat="server" AutoPostback="True" />
After that you should be able to handle the SelectedIndexChanged event for the DropDownList in your code-behind
Protected Sub myDropDownList_SelectedIndexChanged(sender As Object, e As EventArgs) Handles myDropDownList.SelectedIndexChanged
' Lookup the selected item and redirect here
' (This assumes that you've bound your URL to redirect to the value of the item,
' and not the display text. Use SelectedItem.Text if the URL is being displayed
Response.Redirect(myDropDownList.SelectedItem.Value)
End Sub
Try This
Public Class WebForm1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Private Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged
Response.Redirect(DropDownList1.SelectedItem.Text)
End Sub
End Class
I am trying to implement an update panel on my web page. when I add this, everything works fine:
<script runat="server">
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Me.Label2.Text = Date.Now.ToString
End Sub
</script>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<fieldset>
<asp:Label ID="label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button2" runat="server" Text="Button" />
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
<asp:TextBox ID="TextBox1" runat="server" Height="289px" TextMode="MultiLine"
Width="663px" ReadOnly="True"></asp:TextBox>
The problem comes when I try to do some stuff on the on_load event of the application. in the code behind, i try to do this:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Me.Load
If Not IsPostBack Then
....a function that produces a very long xml string
Me.TextBox1.Text ="<f"
End If
End Sub
This will cause the event to not occur. If i change the "<" from the string, all is well. why cant I have "<" in my strings? This is important because i wont allow me to put an xml string in the text box.
any help would be great!
Try using << rather than <
I have a GridView which is continually rebound using a timer and is within an updatePanel so the page doesn't refresh continually (each row has a countdown sequence so the gridview needs to continually get updated)
Inside the gridview i have an imagebutton with an OnClick method. Previously to get the OnClick method to fire I would make sure the gridView wasn't in an UpdatePanel and that the pageload databinding of the gridview was in an "If Not IsPostBack".
With the Timer though i can't have the gridview binding an an "If Not IsPostBack" and it needs to be in an UpdatePanel.
Is there a way to use an UpdatePanel and "If Not IsPostBack" and still get the OnClick method to be called?
Thanks
Here's some of the code, if my explanation didn't make complete sense:
UpdatePanel/Timer/GridView
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Timer ID="timerCountDown" runat="server" Interval="1000" OnTick="timerCountDown_Tick"></asp:Timer>
<asp:GridView ID="gridBuildQueue" runat="server" AutoGenerateColumns="False"
GridLines="none" ShowFooter="false" ShowHeader="false" Width="100%">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton runat="server" ID="cmdCancelBuild" ImageUrl="~/images/cancel.jpg" OnClick="ImageButton_Click"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
OnTick timer method:
Protected Sub timerCountdown_Tick(ByVal sender As Object, ByVal e As EventArgs)
Me.gridBuildQueue.DataBind()
End Sub
ImageButton_Click method (which is currently never called):
Protected Sub ImageButton_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
Dim imageButton As ImageButton = CType(sender, ImageButton)
Dim row As GridViewRow = CType(imageButton.NamingContainer, GridViewRow)
Dim button As ImageButton = DirectCast(row.FindControl("cmdCancelBuild"), ImageButton)
etc...
End Sub
You need to use GridView control events especially - RowCommand event.
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:GridView
ID="gridBuildQueue"
runat="server"
AutoGenerateColumns="False"
GridLines="none"
ShowFooter="false"
ShowHeader="false"
Width="100%"
onrowcommand="gridBuildQueue_RowCommand"
>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton
runat="server"
ID="cmdCancelBuild"
ImageUrl="~/images/cancel.jpg"
CommandName="cmd"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="gridBuildQueue" EventName="RowCommand" />
</Triggers>
</asp:UpdatePanel>
Code behind:
protected Sub gridBuildQueue_RowCommand(ByVal sender As Object,ByVal e as GridViewCommandEventArgs)
if e.CommandName="cmd" Then
....
End If
End sub
In addition to RowCommand event, you must have to add AsyncPostBackTrigger entry for RowCommand event. (Set UpdatePanel.Triggers collection).
DEMO:
Markup
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Timer ID="Timer1" runat="server" Interval="1000">
</asp:Timer>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="GridView1" EventName="RowCommand" />
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
Code-Behind
Dim lst As New List(Of String)
Protected Sub GridView1_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
Label1.Text = DateTime.Now
End Sub
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
If IsNothing(Session("lst")) Then
Session("lst") = lst
End If
GridView1.DataSource = lst
GridView1.DataBind()
End If
End Sub
Protected Sub Timer1_Tick(sender As Object, e As System.EventArgs) Handles Timer1.Tick
lst = Session("lst")
lst.Add(DateTime.Now.ToString())
GridView1.DataSource = lst
GridView1.DataBind()
End Sub