I have one page which is placed in the Master Page.
In the master page I have 1 dropdown and one GridView, dropdown is display the category, based on the dropdown list selection it will display the list of videos in the Grid.
In the content page I have the video player, in the page load it will play the video by default.
But when I choose the drop down list which is available in the master page, the page is refreshing, SO the video is start play from the first.
The content page should not refresh, So the video will continuously play.
How can I stop the page refresh in the content page?
All are in master page.
`<asp:UpdatePanel ID="up1" runat="server" UpdateMode="Conditional">
<asp:DropDownList ID="drp_Channel" Width="220px" CssClass="ddl"
AutoPostBack="true" runat="server"
onselectedindexchanged="drp_Channel_SelectedIndexChanged">
<asp:ListItem>-- Select Channels --</asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="up2" runat="server" UpdateMode="Conditional">
<asp:GridView ID="grd_Video" runat="server" AutoGenerateColumns="False" OnRowCommand="LinkName"
GridLines="None" ShowHeader="False" Width="100%" EmptyDataText="No Videos Found" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="img_Video" runat="server" BorderColor="#666699" CssClass="imgbox"
ImageUrl='<%#(string)FormatImageUrl((string)Eval("Video_Thumbnail")) %>'
CommandName="imgClick" CommandArgument='<%# Bind("Video_ID")%>'
BorderWidth="0px" Height="40px" ToolTip="Click to view video" Width="50px"
BorderStyle="Double" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnk_VideoName" runat="server" ToolTip="Click to view video"
CommandName="lnkClick" CommandArgument='<%# Bind("Video_ID")%>'
Text='<%# DataBinder.Eval(Container, "DataItem.Video_Name") %>'
CssClass="linkVideo" Width="130px"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="#cccccc" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>`
in code behind for binding grid,
DataTable dt1Video = new MDBusiness.MDSUser().GetVideo(intNetId, intChanId, intCatId);
grd_Video.DataSource = dt1Video;
grd_Video.DataBind();
up1.Update();
up2.Update();
Set AutoPostBack = "False" on your dropdownlist to stop the postback from occurring. Users will then be able to change the dropdownlist without anything happening.
You'll need to use AJAX with your dropdownlist if you want to be able to use it without the postback.
for a quick answer
Install ASP.NET AJAX library
Wrap the GridView in a UpdatePanel
Set the trigger to be the DropDownList
Done :)
Remember to see this Screencast... it is exactly what you are after!
Related
I have a ajaxtoolkit combobox inside a gridview and it works perfectly, but the problem is when I click the dropdown button the list overlaps the page so I want to limit the number to be displayed to 10 items per scroll. Next problem is when I try to add an update panel to the page, It destroys the rendering of the combobox. How can I solve this? Thanks in advance
here is my code for the combobox inside the gridview
<asp:GridView CssClass="pad" ID="dgvOrder" runat="server" BorderStyle="Double" AutoGenerateColumns="False" OnRowDataBound="dgvOrder_RowDataBound" OnRowDeleting="dgvOrder_RowDeleting" HorizontalAlign="Center" >
<Columns>
<asp:TemplateField HeaderText="No." AccessibleHeaderText="No.">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Description" AccessibleHeaderText="Description">
<ItemTemplate >
<ajaxToolkit:ComboBox ID="ddlItems" AutoPostBack="True" AppendDataBoundItems="True" onmouseover="this.size=4;" onmouseout="this.size=1;" DataTextField="item_desc" DataValueField="item_id" runat="server" AutoCompleteMode="Suggest" ItemInsertLocation="Prepend" OnSelectedIndexChanged="ddlItems_SelectedIndexChanged" DropDownStyle="DropDown" BorderStyle="Double" ></ajaxToolkit:ComboBox> <br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Please pick an item" ControlToValidate="ddlItems"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Inventory Code" HeaderText="Inventory Code">
<ItemTemplate>
<asp:Label ID="lblInvCode" runat="server" Text=""></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Qty" HeaderText="Qty">
<ItemTemplate>
<asp:TextBox ID="txtQty" runat="server" OnTextChanged="txtQty_TextChanged" AutoPostBack="True" onkeyup ="ValidateText(this);"></asp:TextBox><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator23" runat="server" ErrorMessage="Please input qty" ControlToValidate="txtQty"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="UOM" HeaderText="UOM">
<ItemTemplate>
<asp:Label ID="lblUOM" runat="server" Text=""></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="SOQ" HeaderText="SOQ">
<ItemTemplate>
<asp:Label ID="lblSOQ" runat="server" Text=""></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Reason" HeaderText="Reason">
<ItemTemplate>
<asp:TextBox ID="txtReason" runat="server" Enabled="False"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
and here is my code for the updatepanel
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
</ContentTemplate>
<Triggers>
(whole page inside)
<asp:AsyncPostBackTrigger ControlID="btnSearch" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="txtIdNo" EventName="TextChanged" />
</Triggers>
</asp:UpdatePanel>
Long Item Lists / Multiple Input Controls
All of the items in a ComboBox's list will be rendered to the web page it exists in. The AutoCompleteExtender, on the other hand, retrieves items from its ServiceMethod after the page is rendered. When your ComboBox contains a rather long list of items, or when you have a relatively large number of ComboBoxes on the same page (or within the same UpdatePanel), load times could be slowed down significantly. When ComboBoxes perform slowly because of the amount of markup they must render to the browser, an AutoCompleteExtender can be used instead to increase performance.
<ajaxToolkit:ComboBox ID="ComboBox1" runat="server"
DropDownStyle="DropDown"
AutoCompleteMode="None"
CaseSensitive="false"
RenderMode="Inline"
ItemInsertLocation="Append"
ListItemHoverCssClass="ComboBoxListItemHover"
<asp:ListItem>...</asp:ListIem>
...
For more information your can look it in this link.
I have a gridview which contains images (populated dynamically from database) and dropdownlist which contains two values. First column contains checkbox. I want to insert selected checkbox's images and dropdown values to a new table on button click. What may be the suitable way?
Here is the grid view:
<asp:GridView ID="gvDetails" runat="server" AutoGenerateColumns="false" AllowPaging="true"
EmptyDataText="No images found" OnPageIndexChanging="gvDetails_PageIndexChanging" PageSize="5">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="CheckUncheckAll"/>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID ="CheckBox2" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:Image ID="imgPreview" ImageUrl='<%#
"ImageHandler.ashx?imgID="+ Eval("ID") %>' runat="server"
Height="80px" Width="80px" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dropdown" ItemStyle-Width="50px">
<ItemTemplate>
<asp:DropDownList ID="dpdListEstatus" runat="server" OnSelectedIndexChanged="dpdListEstatus_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem>A</asp:ListItem>
<asp:ListItem>B</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
Loop with gridview rows
Find for the checkbox control
Check if its Checked property is true
If yes, call insert statement
Set the values you want to get from image and dropdownlist. Of course you need to use findcontrol on it too.
Dim cbSelect As CheckBox, imgToInsert As Image, ddlStatus As DropDownList
For Each r As GridViewRow In gvDetails.Rows
cbSelect = r.Cells(0).FindControl("CheckBox2")
If cbSelect.Checked Then
imgToInsert = r.Cells(1).FindControl("imgPreview")
ddlStatus = r.Cells(2).FindControl("dpdListEstatus")
'Insert statement goes here...
End If
Next r
Let me start off by saying I know how to use CausesValidation and ValidationGroup. I have bizarre situation where I have an Ajax Tab container. Each tab has a gridview and the rows that generate in the gridviews all have a TemplateField containing an 'Add' button. The buttons in the gridview and tab containers all use ValidationGroup to prevent any cross contamination and all the 'Add' buttons are set to CausesValidation = "false"
I just added the last gridview and the 'Add' button triggers all validators on the page. Once more the 'Add' button is set as CausesValidation = "false" so there is NO reason for it to behave in this fashion. I even set this value on the front end AND in the code behind.
For attempts I have tried the suggestions in these links: "Solution 1" and "Solution 2"
Has anyone else come across this and found a solution?
Edit Request for code:
I will post only the Tab Panel in question as the whole container is almost 500 lines
<asp:TabPanel ID="tab_Browse" runat="server" HeaderText="Browse">
<ContentTemplate>
<table id="browseTable">
<tr>
<td>Category</td>
<td>
<asp:DropDownList ID="browseDDL" runat="server" AppendDataBoundItems="True">
<asp:ListItem Text="All categories" Value="999"></asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:Button ID="btnBrowse" runat="server" Text="Browse" ValidationGroup="vgBrowse" OnClick="btnBrowse_Click" />
</td>
</tr>
</table>
<asp:GridView ID="gvBrowse" runat="server" AutoGenerateColumns="false" AllowPaging="true" PageSize="8"
OnPageIndexChanging="gvBrowse_PageIndexChanging" DataKeyNames="foodId"
OnRowDataBound="gvBrowse_RowDataBound" Width="790px">
<Columns>
<asp:TemplateField HeaderText="Food ID" Visible="false">
<ItemTemplate>
<%# Eval("foodId") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<%# Eval("Shrt_Desc") %> (100g)
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Calories" ItemStyle-Width="50px">
<ItemTemplate>
<%# Eval("cals") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Fat Grams" ItemStyle-Width="75px">
<ItemTemplate>
<%# Eval("fat") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Carbs" ItemStyle-Width="50px">
<ItemTemplate>
<%# Eval("carbs") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="110px">
<ItemTemplate>
<asp:Button ID="browseAdd" runat="server" CausesValidation="false" Text="Add to meal" CommandArgument="Standard" OnClick="showingEntry" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle CssClass="gvRowStyle" />
<HeaderStyle CssClass="gvHeader" />
<AlternatingRowStyle CssClass="altRow" />
</asp:GridView>
</ContentTemplate>
</asp:TabPanel>
Edit 2 Another interesting tidbit. If I put OnClientClick="alert(Page_IsValid)" on my add button it returns true even though the validators in the others tabs are triggered. if i click the button a second time it returns false and my codebehind fails as if the page posted back but skipped the OnDataBound method
I ended up resolving this problem by preloading the gridview with an empty row. Makes no sense as to why this resolved the problem, but it does.
An event bound to a DropDownList in a standalone GridView obviously would work in this fashion , but things are bit more complicated in this scenario.
The event does not fire for the DropDownList. What's interesting is the event bound to the Button Does fire. Not sure what the difference would be between the DropDownList and TextBox.
I've tried both OnSelectedIndexChanged and OnTextChanged - neither work.
The nesting is as follows:
GridView A
Ajax Accordion
GridView B (With DropDownList)
<AjaxToolkit:AccordionPane ID="AccordionPane1" runat="server">
<Header>
</Header>
<Content>
<asp:GridView runat="server" ID="gv" AutoGenerateColumns="false"
BorderWidth="0" AlternatingRowStyle-BorderStyle="None" ShowFooter="true">
<Columns>
<asp:TemplateField HeaderText="Id">
<ItemTemplate>
<asp:Label runat="server" ID="lblId" Text='<%# Eval("Id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Type">
<ItemTemplate>
<asp:Label runat="server" ID="lblType"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList runat="server" ID="ddlType" OnTextChanged="ddlType_SelectedIndexChanged"
AutoPostBack="true">
</asp:DropDownList>
<asp:Button runat="server" ID="btnTest" OnClick="btnTest_Click" Text="TEST" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</Content>
Thank you!
UPDATE
Turns out this had nothing to do with the nested GridViews or Accordion.
After adding the following, the event now successfully fires:
if (!Page.IsPostBack)
Populate(object);
Turns out this had nothing to do with the nested GridViews or Accordion.
After adding the following, the event now successfully fires:
if (!Page.IsPostBack)
Populate(obj);
IGNORE THIS:
I was rebinding the grid in the Onload method.
I have a grid view with some textboxes, which I have to wrap in a UpdatePanel Control. So it looks like this:
<asp:UpdatePanel ID="upDistribution" runat="server" OnLoad="upDistribution_OnLoad">
<ContentTemplate>
<asp:GridView ID="gvDistributions" runat="server" AutoGenerateColumns="false"
OnRowDataBound="gvDistributions_RowDataBound"
CssClass="TallCells ContrastTable MaxWidth LeftHeaders"
GridLines="Both" ShowFooter="True" style="">
<RowStyle HorizontalAlign="Left" />
<EmptyDataTemplate>
No pricing history data found.
</EmptyDataTemplate>
<Columns>
<asp:TemplateField HeaderText="PriceA">
<ItemTemplate>
<asp:TextBox ID="txtPriceA" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DistPrice">
<ItemTemplate>
<asp:TextBox ID="txtDistPrice" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
There is a button "Save" when I would like to get the value entered for the txtboxes. If there is no UpdatePanel around the GV, i can can easily get the txtbox values like:
((TextBox)gvDistributions.Rows[0].Cells[0].FindControl("txtPriceA")).Text
But when, the GridView is wrapped with UpdatePanel, the above statement returns the value that was set on the page load.
How can I get the value of the text box without getting rid of the updatePanel. I need the update panel, because the number of rows, and dates are dependent on another variable in another user control.
As per my understanding, you should use a trigger for the update panel which is something like below.
<asp:UpdatePanel ...>
<ContentTemplate>
...
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
Hope this helps!!
Use your TextBoxes with their AutoPostBack property set True
<asp:TextBox ID="txtPriceA" runat="server" AutoPostBack="True"/>
I was rebinding gridview in the onLoadMethod