I have a treeview, I want to check all the children when I clicked the parent node from javascript. I have followed this link from stackoverflow. This process is currect. I have tested it with alert message also. The ID which is showing in the alert message is exactly right ID of the child. And the method is been setting the status also. Code is reaching here childChkBoxes[i].checked = check;
function CheckUncheckChildren(childContainer, check) {
var childChkBoxes = childContainer.getElementsByTagName("input");
var childChkBoxCount = childChkBoxes.length;
for (var i = 0; i < childChkBoxCount; i++) {
alert("Childer lenght = "+childChkBoxes.length +" childern ID "+ childChkBoxes[i].id + " Parent checked state =" + check);
childChkBoxes[i].checked = check;
}
}
even the check box of child is not been checking in UI. What might be the problem. This code is working for every one. Why not working here, I am displaying the treeview in a modelpopupextender control. Is anything wrong with my browser, I am using firefox. Is anything wrong with my treeview design.
her it is
<asp:TreeView ID="tvFolderSelect" runat="server" RootNodeStyle-ForeColor="Black"
CssClass="foldertree" LeafNodeStyle-ForeColor="Black" LeafNodeStyle-Font-Bold="false"
ParentNodeStyle-ForeColor="Black" Width="100%" Style="margin: 3px 0 0 -16px;"
OnTreeNodePopulate="tvFolderSelect_TreeNodePopulate" onclick="OnTreeClick(event);"
ShowCheckBoxes="All" >
<LeafNodeStyle Font-Bold="False" ForeColor="Black" CssClass="foldertreeleafnode"
ImageUrl="~/images/img_dms/sm_fldr.png" />
<ParentNodeStyle Font-Italic="True" ImageUrl="~/images/img_dms/sm_fldr.png" Font-Underline="True"
CssClass="foldertreeparentnode"/>
<NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Black" HorizontalPadding="0px"
NodeSpacing="0px" VerticalPadding="0px" />
<RootNodeStyle ForeColor="Black" CssClass="foldertreerootnode" />
<SelectedNodeStyle Font-Underline="False" HorizontalPadding="0px" VerticalPadding="0px" />
</asp:TreeView>
I tried this code in normal aspx page(not in modelpopupextender). And it is working well
Related
I have got a infragistics webdatagrid in my page, and on top of that page, i have got a webdatamenu with 2 buttons, one for refreshing the page, and the other for save the data from the grid.
What i am doing is a day scheduler.
here is my webdatagrid..
<ig:WebDataGrid ID="WebDataGridPlaneamentoHorarios" Visible="false" runat="server" Height="500px"
AutoGenerateColumns="False" Width="1300px" BorderColor="#666666"
ShowFooter="True" EnableDataViewState="True" >
<Columns>
<ig:BoundDataField DataFieldName="Numero" Key="Numero" Width="100px" Hidden="false">
<Header Text="Número" />
</ig:BoundDataField>
<ig:BoundDataField DataFieldName="Nome" Key="Nome" Width="100px">
<Header Text="Nome" />
</ig:BoundDataField>
<ig:BoundDataField DataFieldName="Descricao" Key="Descricao" Width="150px" Hidden="false">
<Header Text="Profissão" />
<Footer TemplateId="footerTemplate" />
</ig:BoundDataField>
<ig:TemplateDataField Key="Segmentos" Width="1510px" Hidden="False">
<ItemTemplate>
<uc1:Segmento ID="Segmento1" runat="server" />
</ItemTemplate>
<HeaderTemplate >
<uc5:HeaderControl ID="SegHed" runat="server"/>
</HeaderTemplate>
<FooterTemplate >
<div id="Quant" runat="server"> <uc2:SegNecessidades ID="SegNecessidades" runat="server" /></div>
<br /><br /> <div id="Totais" runat="server"><uc2:SegNecessidades ID="SegNecessidades2" runat="server" /></div>
<br /><br />
</FooterTemplate>
</ig:TemplateDataField>
<ig:BoundDataField DataFieldName="IDProfissao" Width="50px" Hidden="true" Key="IDProfissao">
<Header Text="IDProfissão" />
</ig:BoundDataField>
</Columns>
<Templates>
<ig:ItemTemplate ID="WebDataGridPlaneamentoHorariosTemplate2" runat="server"
TemplateID="footerTemplate">
<Template >
<uc3:FooterControl ID="FooterC" runat="server" />
</Template>
</ig:ItemTemplate>
</Templates>
</ig:WebDataGrid>
Everything is working fine, on refresh, the data is loaded...the problem is when i try to save the changes...
protected void WebDataMenuOptions_ItemClick(object sender, Infragistics.Web.UI.NavigationControls.DataMenuItemEventArgs e)
{
if (e.Item.Key == "btnRefrescar")
{
foreach (GridRecord row in WebDataGridPlaneamentoHorarios.Rows)
{
GridRecordItem itm = row.Items[3];
string id = row.Items[0].Text;
Control control = itm.FindControl("Segmento1");
DataTable DTblHorarioById = dbcHorariosEscalas.GetHorarioById(id, dt);
Segmentos seg = (Segmentos)control;
seg.AddSegmento(id, DTblHorarioById);
//this is to load the schedule of the user,,,,
}
}
else if(e.Item.Key == "btnGuardar")
{
foreach (GridRecord row in WebDataGridPlaneamentoHorarios.Rows)
{
GridRecordItem itm = row.Items[3];
string id = row.Items[0].Text;
Control control = itm.FindControl("Segmento1");
}
}
}
So the code is the same in both buttons, i am trying to find the user control called Segmento1, that is in the 4 column...
Now the code works when refresh button is pressed, the user control is found, but when i press the button save, the control is null...what is the problem...i am going nuts with this, because yesterday it was working, and then today it stoped, i think is one of those programming problems when the code works and stop working just because he wants..
I'm developing a gridview in which you can download multiple files with one button.
Here's my gridview:
<asp:GridView ID="grdvHistorialMensajes" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="4" AllowSorting="true"
EmptyDataText="No Hay Mensajes Enviados" ForeColor="#333333"
GridLines="None" CellSpacing="1"
onpageindexchanging="grdvHistorialMensajes_PageIndexChanging"
onrowcommand="grdvHistorialMensajes_RowCommand"
onsorting="grdvHistorialMensajes_Sorting">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="CorreoCliente" HeaderText="Correo Del Cliente" SortExpression="CorreoCliente" />
<asp:BoundField DataField="CorreosAdicionales" HeaderText="Correos Adicionales" SortExpression="CorreosAdicionales" />
<asp:BoundField DataField="Tema" HeaderText="Tema" SortExpression="Tema" />
<asp:BoundField DataField="Mensaje" HeaderText="Mensaje" SortExpression="Mensaje" />
<asp:TemplateField HeaderText="Fecha" SortExpression="Fecha">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Fecha", "{0:dd/MM/yyyy}")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tbxFecha" runat="server" Text='<%#Bind("Fecha","{0:dd/MM/yyyy}") %>' ValidationGroup="gpEdicionAgenda">
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Hora" HeaderText="Hora" SortExpression="Hora" />
<asp:BoundField DataField="Archivos" HeaderText="Archivos" SortExpression="Archivos" />
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="imgBtnDescargarArchivos" runat="server"
CommandArgument='<%# Eval("IdMensaje")%>' CommandName="Descargar" Height="16px"
ImageUrl="~/img/activar.png" ToolTip="Descargar" Width="16px" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="imgBtnVerMas" runat="server"
CommandArgument='<%# Eval("IdMensaje")%>' CommandName="VerMas" Height="16px"
ImageUrl="~/img/search.png" ToolTip="Ver Mas" Width="16px" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
Whenever I click on the "Descargar" RowCommand, I originally used this:
if (e.CommandName == "Descargar")
{
DataTable dt = ConexionBD.GetInstanciaConexionBD().GetArchivosPorMensaje(Convert.ToInt32(e.CommandArgument));
foreach (DataRow dr in dt.Rows)
{
string strArchivo = dr["Nombre"].ToString();
string strExtension = Path.GetExtension(strArchivo).ToLower();
Response.Write("<script>window.open('/Archivos/" + strArchivo + "');</script>");
}
}
When I clicked, if that row had let's say 1 pdf, 1 jpg and 1 doc, it opened both the pdf and the jpg in a different window and the doc would be downloaded. That's exactly what I want. However, I noticed that whenever a new page is opened (in the case of the pdf and jpg) all the font in the page is altered. So I wanted to find a solution and then I tried this:
if (e.CommandName == "Descargar")
{
DataTable dt = ConexionBD.GetInstanciaConexionBD().GetArchivosPorMensaje(Convert.ToInt32(e.CommandArgument));
foreach (DataRow dr in dt.Rows)
{
string strArchivo = dr["Nombre"].ToString();
string strExtension = Path.GetExtension(strArchivo).ToLower();
ClientScript.RegisterStartupScript(this.GetType(), "myFileOpenScript", "<script>window.open('/Archivos/" + strArchivo + "');</script>");
}
}
When I open a pdf file, the font is not altered this time, however, It would only open/download the first file that appears int dt.Rows[0] (dt.Rows[1] on won't open). I suppose that a Response.Write can be deployed multiple times, however, a ClientScript.RegisterStartupScript probably can only be executed once.
Is there another method I can use to not alter the page's letter font and to open multiple files with a single click?
Or how could I execute ClientScript.RegisterStartupScript multiple times??
Thanks In Advance
A little extra information information would be helpful. You aren't limited from using RegisterStatupScript more than once, but you are limited from registering the same type/key combination more than once (this is a feature, not a limitation).
If you need to register different scripts, use a unique key. If you are simply doing a postback, re-registering the startup script will/should work.
http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.aspx
ClientScript.RegisterStartupScript(this.GetType(),
"myFileOpenScript",
"<script>window.open('/Archivos/" + strArchivo + "');</script>");
The script key here is myFileOpenScript.
A client script is uniquely identified by its key and its type.
Scripts with the same key and type are considered duplicates. Only one
script with a given type and key pair can be registered with the page.
Attempting to register a script that is already registered does not
create a duplicate of the script.
http://msdn.microsoft.com/en-us/library/asz8zsxy.aspx
You can use Guid.NewGuid() to generate a different key each time. And you would probably want to use
RegisterStartupScript(Type, String, String, Boolean)
instead. The last parameter (boolean) tells it to create the script tags for you, so the script parameter can contain only your code not worrying about the tags.
Since Jamie Tores answer lacks an example
This is correct
ScriptManager.RegisterStartupScript(Page, GetType(), "setDatePickerStartDate", "javascript:setDatePickerStartDate('" + s_capstoneStartDate + "'); ", true);
ScriptManager.RegisterStartupScript(Page, GetType(), "setDatePickerEndDate", "javascript:setDatePickerEndDate('" + s_capstoneEndDate + "'); ", true);
This is wrong since the 3rd parameter is the same in both
ScriptManager.RegisterStartupScript(Page, GetType(), "Javascript", "javascript:setDatePickerStartDate('" + s_StartDate + "'); ", true);
ScriptManager.RegisterStartupScript(Page, GetType(), "Javascript", "javascript:setDatePickerEndDate('" + s_EndDate + "'); ", true);
You're right to avoid using Response.Write in an event handler like that: it executes before the Render phase of the page lifecycle, and therefore outputs at the top of the HTML page.
You could use a StringBuilder to build the script in the foreach DataRow loop, then register it once.
I know that I'm a bit late to the party, but I needed to accomplish the same thing. With the knowledge that #JaimeTorres provided that there has to be a unique key, I just made a static method where you pass in the Page and the Message, and the method creates an arbritrary "key" with a basic Do....While loop and keeps checking the keys until we find the first one that hasn't been used yet. Then it uses that to display the message. Works just fine for my purposes, maybe someone else can make use of it if they find this answer!
/// <summary>
/// Shows a basic MessageBox on the passed in page
/// </summary>
/// <param name="page">The Page object to show the message on</param>
/// <param name="message">The message to show</param>
/// <returns></returns>
public static ShowMessageBox(Page page, string message)
{
Type cstype = page.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = page.ClientScript;
// Find the first unregistered script number
int ScriptNumber = 0;
bool ScriptRegistered = false;
do
{
ScriptNumber++;
ScriptRegistered = cs.IsStartupScriptRegistered(cstype, "PopupScript" + ScriptNumber);
} while (ScriptRegistered == true);
//Execute the new script number that we found
cs.RegisterStartupScript(cstype, "PopupScript" + ScriptNumber, "alert('" + message + "');", true);
}
I usually use this method to show alert and I can call it whenever I need.
public class BasePage : System.Web.UI.Page {
public void ShowNotif(string sMessage) {
ScriptManager.RegisterStartupScript(Page, GetType(), Guid.NewGuid().ToString(), "alert('" + sMessage.Replace("'", "\'") + "'); ", true);
}
}
It means I can run Javascript code multiple times.
Usage : Every Webform Class, extend BasePage like this :
public partial class FinanceHostToHost : BasePage{ //Not extend System.Web.UI.Page
....
}
Function call :
ShowNotif("Hello");
ShowNotif("World");
ShowNotif("Any message");
ShowNotif("Message again");
I have a code that contains an ASPxGridView and a ASPxCheckBox and Label within in like:
<dx:ASPxGridView ID="gvTableSearchHomes" runat="server" DataSourceID="XmlHomes" Width="341px"
CssClass="tableViewSearchGrid" ClientInstanceName="gvTableSearchHomes"
AutoGenerateColumns="False" EnableRowsCache="false" KeyFieldName="ID">
<%--<Columns>--%>
<%-- DXCOMMENT: Within ASPxGridView, add a column whose values will participate in filtering --%>
<%--<dx:GridViewDataTextColumn FieldName="Address">
<PropertiesTextEdit NullText="Search your home"></PropertiesTextEdit>
<Settings AllowAutoFilterTextInputTimer="True" AutoFilterCondition="Contains" />
</dx:GridViewDataTextColumn>
</Columns>--%>
<Templates>
<%--DXCOMMENT: Configure the grid's DataRow template in accordance with data source fields --%>
<DataRow>
<div class="gvItem">
<dx:ASPxCheckBox ID="ChkBookList" runat="server"></dx:ASPxCheckBox>
<dx:ASPxLabel ID="Address" runat="server" CssClass="address" Text='<%# Utils.ExtractFirstRow(Eval("Address")) %>' />
<%--<p><dx:ASPxLabel ID="Address2" runat="server" CssClass="address2" Text='<%# Utils.ExtractSecondRow(Eval("Address")) %>' /></p>
<p><dx:ASPxLabel ID="Price" runat="server" CssClass="price" Text='<%# Utils.GetPrice(Eval("Price")) %>' /></p>--%>
</div>
</DataRow>
</Templates>
<SettingsPager Visible="false" PageSize="1000" />
<Settings ShowVerticalScrollBar="True" ShowFilterRow="true" ShowColumnHeaders="false"/>
<SettingsBehavior AutoExpandAllGroups="true" AllowSelectSingleRowOnly="true" AllowSelectByRowClick="true"/>
<ClientSideEvents
Init="function(){ hr.TableViewLandscape_Adjust(); }"
EndCallback="function(){ hr.TableViewLandscape_Adjust(); }"
SelectionChanged="OnGvTableSearchHomesSelectedChanged" />
<Styles>
<SelectedRow ForeColor="White"></SelectedRow>
</Styles>
I am not able to access these cotnrols through C# code. Can anybody help me. Please
Check the documentation methods to find controls in different gridview templates.
e.g. ASPxGridView.FindRowTemplateControl Method
Source: http://developmentsolutionsjunction.blogspot.in/2011/11/find-controls-in-dataitemtemplate-of.html
//markup
<dx:ASPxGridView ID="grvTest" AutoGenerateColumns="False" runat="server" DataSourceID="SqlDataSource1"
OnHtmlRowPrepared="grvTest_HtmlRowPrepared" OnHtmlRowCreated="grvTest_HtmlRowCreated">
<Columns>
<dx:GridViewDataTextColumn Caption="RowID" Name="colRowID" VisibleIndex="0" Width="20px">
<DataItemTemplate>
<dx:ASPxLabel ID="lblRowID" runat="server" Text='Label'>
</dx:ASPxLabel>
</DataItemTemplate>
</dx:GridViewDataTextColumn>
//accessing template control in code-behind
protected void grvTest_HtmlRowCreated(object sender, ASPxGridViewTableRowEventArgs e)
{
if (e.RowType != GridViewRowType.Data) return;
ASPxLabel label = grvTest.FindRowCellTemplateControl(e.VisibleIndex, null,
"lblRowID") as ASPxLabel;
label.Text = (e.VisibleIndex + 1).ToString();
}
example code:
ASPxGridView grid = (ASPxGridView)sender;
ASPxPageControl myPages = grid.FindEditFormTemplateControl("CityEditTabs")
as ASPxPageControl;
References:
How can I write events for the controls used in my Grid templates
Some GridView code snippets to understand gridview concepts
Identify the VisibleIndex or RowHandle to get the control in particular template that you have created in your markup.
Hope above example will help you to solve your problem.
thanks I solved mi problem. I put this
Protected Sub GvEncuesta_HtmlRowCreated(sender As Object, e As ASPxGridViewTableRowEventArgs)
If (e.RowType <> GridViewRowType.Data) Then Return
Try
Dim cmbRespuesas As ASPxComboBox = GvEncuesta.FindRowCellTemplateControl(e.VisibleIndex, Nothing, "ASPxCmbRespuestas")
cmbRespuesas.IncrementalFilteringMode = IncrementalFilteringMode.Contains
cmbRespuesas.Visible = True
cmbRespuesas.DataSource = wcfCap.RetrieveRespuestaEncuestaxEstado(1)
cmbRespuesas.ValueField = "Cod_Respuesta"
cmbRespuesas.TextField = "Nombre_Respuesta"
cmbRespuesas.DataBindItems()
Catch ex As Exception
End Try
End Sub
I am binding the XML Data to treeview using XMLDataSource. Its working fime, but when the Number of nodes and childnodes increases, the treenode expand and to display the content in
iframe takes moer time.
<asp:TreeView ID="TreeView1" OnSelectedNodeChanged = "OnClick" runat="server"
ExpandDepth="0" ShowExpandCollapse="true" ForeColor="Red" Font-Underline = "false"
ondatabinding="TreeView1_DataBinding" CollapseImageUrl = "Resources/TocColapse.bmp" ExpandImageUrl = "Resources/TocParent.bmp" Font-Names="Arial" >
<SelectedNodeStyle Font-Underline="false" BackColor="White" ForeColor="#0483e0" />
<NodeStyle Font-Size="11pt" ForeColor="white" HorizontalPadding="5px"
NodeSpacing="0px" VerticalPadding="0px" Font-Underline = "false" />
<ParentNodeStyle ForeColor="#0483e0" Font-Underline = "false" />
<LeafNodeStyle ForeColor="#0483e0" Font-Underline = "false" ImageUrl = "Resources/TocChild.bmp" />
</asp:TreeView>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" XPath="/*/*" EnableCaching = "false" ></asp:XmlDataSource>
In OnDataBinding event of treeview I implemented the following code:
TreeNodeBinding[] TreeNode = new TreeNodeBinding[Count];
for (int i = 0; i < Count; i++)
{
TreeNode[i] = new TreeNodeBinding();
TreeNode[i].DataMember = TableOfContents[i].GetElementName();
TreeNode[i].TextField = TableOfContents[i].GetFirstAttributeName();
TreeNode[i].ValueField = TableOfContents[i].GetSecondAttributeName();
// TreeNode[i].Target = "contentFrame";
TreeView1.DataBindings.Add(TreeNode[i]);
}
Of course it does. Take a look towards lazy loading.
What about setting EnableCaching to "true"?
Also, are you sure that you need to display the whole xml? You could provide the user some filtering which reduces the size of the displayed xml.
Try for populate on demand.
I used populate on demand when it was taking so long time in loading the treeview in the client side.
Here is what I am doing. I create two buttons in a header row of a gridview that i created. The buttons are +page and -page. When -page is hit I remove the paging and all the data goes down the page and -page disappears and +page is there.
Here comes my issue When I hit +page I must be double postbacking because one row of my data disappears. I will provide the code below. What can i do to fix this??
Dim bttnrempag As New Button
bttnrempag.ID = "bttnrempag"
bttnrempag.Text = " Paging"
bttnrempag.CssClass = "bttnMinEG"
bttnrempag.ValidationGroup = "alone"
bttnrempag.Attributes.Add("onclick", "return Paging('1')")
Dim bttnallowpag As New Button
bttnallowpag.ID = "bttnallowpag"
bttnallowpag.Text = " Paging"
bttnallowpag.ValidationGroup = "alone"
bttnallowpag.CssClass = "bttnAddEG"
bttnallowpag.Attributes.Add("onclick", "return Paging('0')")
---------------------How the buttons are added------------------------------------------
Dim row As New GridViewRow(-1, -1, DataControlRowType.Separator, DataControlRowState.Normal)
row.Cells.Add(cell)
cell.Controls.Add(bttnrempag) '36
cell.Controls.Add(bttnallowpag)
----------------------------------------------------------------------------------------
function Paging(remove) {
var gridView = $get('<%=Gridview1.ClientID %>');
var txt2 = $get('<%=TextBox2.ClientID %>');
if (remove == '1') {
txt2.value = '1';
__doPostBack('<%=UpdatePanel1.ClientID %>', '');
return false;
}
else {
txt2.value = '0';
__doPostBack('<%=UpdatePanel1.ClientID %>', '');
return false;
}
Edited
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate >
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" BackColor="White" BorderColor="#E7E7FF"
BorderStyle="None" BorderWidth="1px" CellPadding="3"
DataSourceID="SqlDataSource1" Font-Names="Comic Sans MS" Font-Size="XX-Small"
Caption = '<table border="" width="100%" cellpadding="3" cellspacing="0" bgcolor="#4A3C8C"><tr><td style = "font-size:X-large;font-family:Arial CE;color:White"><b>Ordering/Receiving Log</u></td></tr></table>'
Font-Bold="True" PageSize="15" >
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<Columns>
Bound Data
</Columns>
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<EmptyDataTemplate>
<head>
<meta http-equiv="refresh" content="5;URL=/Corporate_newpo/ReceivingLog.aspx?">
</head>
<script type="text/javascript" >
var count = 6;
var counter = setInterval("timer()", 1000); //1000 will run it every 1 second
function timer() {
count = count - 1;
if (count <= 0) {
clearInterval(counter);
//counter ended, do something here
return;
}
$get("timer").innerHTML = "The Table will Reload in " + count + " secs";
}
</script>
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="Large"
ForeColor="#993333" Text="No Data was Found for the Selected Filter"></asp:Label><br /><br />
<span id="timer" style="font-size:medium;color:blue"></span>
</EmptyDataTemplate>
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<AlternatingRowStyle BackColor="#F7F7F7" />
<PagerTemplate>
<small 12px""="" style="font-size:xx-small; padding-right">Go To Page</small>
<asp:DropDownList ID="ddlPageSelector" runat="server" AutoPostBack="true"
Font-Size="XX-Small" Height="19px" Width="36px">
</asp:DropDownList>
<asp:ImageButton ID="btnFirst" runat="server" CommandArgument="First"
CommandName="Page" SkinID="pagefirst" />
<asp:ImageButton ID="btnPrevious" runat="server" CommandArgument="Prev"
CommandName="Page" SkinID="pageprev" />
<asp:ImageButton ID="btnNext" runat="server" CommandArgument="Next"
CommandName="Page" SkinID="pagenext" />
<asp:ImageButton ID="btnLast" runat="server" CommandArgument="Last"
CommandName="Page" SkinID="pagelast" />
</PagerTemplate>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
So as you can see, when one or the other is hit I set a textbox to some value then i do a partial postback to my Gridview which is in that Updatepanel.
I suspect it's because you called the "__doPostBack" method. The buttons' normal default click behaviour will perform the Async postback, you probably made it perform another time. Try removing it and see how it goes.
Can you try to put the Click Attribute on the buttons in RowDataBound event declaration??
Cheers.
Try changing your <asp:ImageButtons> to be regular HTML <img> tags.
I've run into this sort of thing before which was hard to diagnose and even harder to explain. See here and here for some buggy behavior that might help. If you have <img> tags with blank src attributes, then the hyperlinks I provided likely explain the problem. If you do not have any blank <img> tags then keep reading for my work around.
In my specific case, it was only happening on some servers (at some client sites) but not others, so I couldn't find any concrete issues with the code. My workaround was to change my <asp:ImageButtons> to regular <img> tags with javascript click events that would call a function to perform the postback, much like your Paging() function.
For some reason, I have found that an <asp:ImageButton> with a client side onclick event of return:confirm('are you sure?'); will stop a postback if the confirm() returns false, however returning false the way you do in your Paging() function after manually calling a __doPostBack does not consistently stop the page from posting back a second time.
Please look at the html as it is rendered on the page:
Every time it's present
<img src=""/>
double postback can happen, for some browser...
This trouble could be resolved setting a default, blank, image for every button
<asp:ImageButton ImageUrl="~/Images/blank.gif"...>
Anyway, this command can be entered in Immediate Window if you put a breakpoint inside Page_Load and allow you to indentify the control that caused postback
Page.Request.Params["__EVENTTARGET"];
I've found a nice solution that works great. It does append it's own handler, but I guess that can be fixed too.
using System.Linq;
private void GridView_OnItemDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
var buttons = e.Row.Cells.OfType<DataControlFieldCell>().SelectMany(item => item.Controls.OfType<ImageButton>());
foreach (ImageButton imageButton in buttons)
{
var argument = imageButton.CommandName + "$" + imageButton.CommandArgument;
imageButton.OnClientClick = this.Page.ClientScript.GetPostBackClientHyperlink(this.GridView, argument) + "; return false;";
}
}
}
Try this, (I don't know why you were using javascript):
bttnrempag.onclick += bttnrempag_Click;
protected void bttnrempag_Click(object sender, EventArgs e)
{
//handle the removal of paging or whatever.
}
You have to provide an image for your ImageButtons. Otherwise the HTML rendered will produce an <img src=""> tag and when this is rendered, it will cause a postback. Try it.