w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Keeping Data in GridView after PostBack
This is by design. The problem here is that the SqlDataSource gets re-created when the page loads it does NOT maintains the selectcommand on postback but rather reverts to the one that was set when the DataSource was created. So you need to tell the the SqlDataSource what it had for SelectCommand when it last loaded correctly. Just store the SQL COMMAND in ViewState and enable encryption to protect the contents by setting ViewStateEncryptionMode on the Page directive. [ Always choose security as a standard ] <%@ Page ViewStateEncyptionMode="Always" %> In your button click event store your new command in view state: ViewState["currentCommand"] = "SELECT * FROM USERS WHERE user_id = 1"; UsersSource.SelectCommand = ViewState["currentCommand"]; GridView1.DataBind(); Now in you

Categories : C#

Refresh gridview data in a page present in the server
You can use asp.net ajax timer control to refresh the page / part of page periodically. The following example shows you can update server time every 5 second. Similarly you will update the GridView. HTML <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:Timer runat="server" id="UpdateTimer" interval="5000" ontick="UpdateTimer_Tick" /> <asp:UpdatePanel runat="server" id="TimedPanel" updatemode="Conditional"> <Triggers> <asp:AsyncPostBackTrigger controlid="UpdateTimer" eventname="Tick" /> </Triggers> <ContentTemplate> <asp:Label runat="server" id="DateStampLabel" /> </ContentTemplate> </asp:UpdatePanel> Code behind protected void UpdateTimer_Tick(ob

Categories : C#

How to refresh a DataBind() after Postback
Reload the datasource in cmdDeleteNews_Click. Then DataBind the databound controls. Protected Sub cmdDeleteNews_Click(sender As Object, EventArgs As e) ' Delete logic here .... ' ' Then reload and DataBind all: Dim items = GetItems() NewsRepeater.DataSource = items NewsRepeater.DataBind() ContentRepeater.DataSource = Items ContentRepeater.DataBind() End Sub

Categories : Asp Net

ASP.NET 4.5 GridView: PostBack of last page
As I was not satisfied with my proposed solution (brought too many issues for future development), I have decided to go the "Control development" way to ensure everything is created correctly. It occurs no matter the type of PagerTemplate I am using - I am using one, the postback does not fire from Last page. Hopefully I am not the only one :-) For those who are experiencing the same issues, I am providing custom control that works OK (of course, does not implement PagerSettings and PagerTemplates, but brings the basic functionality). public class ExtendedGridView : System.Web.UI.WebControls.GridView { protected override void InitializePager(System.Web.UI.WebControls.GridViewRow row, int columnSpan, System.Web.UI.WebControls.PagedDataSource pagedDataSource) { HtmlGenericC

Categories : C#

Error on GridView postback
In the Page Load event you are creating the Grid and add it to Controls collection. So when you are not going for Postback....it will again create the control but will when u try to add it will throw exception. Check it out by debugging the solution.

Categories : C#

return to a specific gridview row on postback
Use ScrollIntoView JS command in conjunction with client-side ID of your dropdown. Add following code to your dropdown's OnSelectedIndexChanged event: ClientScript.RegisterStartupScript(this.GetType(), "hash", "document.getElementById('" + ((DropDownList)sender).ClientID + "').scrollIntoView();", true); On postback it will scroll currently clicked dropdown back into view. OR even try something as simple and straightforward as ((DropDownList)sender).Focus();

Categories : C#

How to remove postback on linkbutton inside gridview?
So just to confirm my answer after our comments, replace this... <asp:TemplateField> <ItemTemplate> <asp:LinkButton ID="linkView" CssClass="View" Text ='<%# Eval("ID")%>' runat="server"></asp:LinkButton> </ItemTemplate> </asp:TemplateField> ...with this... <asp:TemplateField> <ItemTemplate> <a href="#" onclick="return loadViaAjax();"><%# Eval("ID")%></a> </ItemTemplate> </asp:TemplateField> ...where loadViaAjax is a Javascript function which populates your customer fields via AJAX or some other means. Ensure this function returns false to prevent the browser responding to the anchor click. Please mark this as the answer if it works for you.

Categories : Asp Net

Gridview TemplateField checkbox postback behavior in asp.net
Try this <asp:GridView ID="ObjList" runat="server" CssClass="ObjList" AutoGenerateColumns="false" OnRowDataBound="ObjList_RowDataBound" AutoGenerateSelectButton="false" AllowPaging="False"> <Columns> <asp:TemplateField HeaderText="&nbsp"> <HeaderTemplate> <asp:UpdatePanel runat="server"> <ContentTemplate> <asp:CheckBox AutoPostBack="true" ID="chkAll" runat="server" OnCheckedChanged="HeaderChk_Changed" /> </ContentTemplate> </asp:UpdatePanel> <asp:HiddenField ID="LinkNumIndexHead" runat="server" Value="-1" /> </HeaderTemplate> <ItemTemplate>

Categories : Asp Net

Prevent an asynchronous postback from gridview with javascript
The link at this location discusses how to cancel an async postback via JavaScript: http://www.ajaxtutorials.com/ajax-tutorials/cancel-asynchronous-postback-in-c/ The important part is here: <script type="text/javascript"> var instance = Sys.WebForms.PageRequestManager.getInstance(); instance.add_initializeRequest(instance_initializeRequest); function instance_initializeRequest(sender, args) { if (args.get_postBackElement().id == 'btn_Cancel') { instance.abortPostBack(); alert('Postback has been cancelled. Time will not be updated.'); } } </script>

Categories : C#

prevent button inside a gridview to postback using javascript
When button click you can add a loader throught javascript css .loader { position: fixed; z-index: 1000; top: 0; left: 0; height: 100%; width: 100%; -moz-opacity:0.6; /* Mozilla */ opacity: 0.6; /* CSS3 */ -ms-filter: 'progid:DXImageTransform.Microsoft.Alpha(Opacity=40)'; /* first!*/ filter: alpha(opacity=40); /* second!*/ background: #C0C0C0 url('../images/Loader.gif') 50% 50% no-repeat } html <div id="mask" class="loader"> </div> jquery onload $('#mask').css('display', 'none'); jquery on button press $('#mask').css('display', 'block'); after finish click procedure $('#mask').css('display', 'none'); With this way user will click once. After procedure finsished will press

Categories : Jquery

Postback resets the selectedValue of DropdownList inside GridView
RowDataBound gets fired every time (irrespective of whether the page is PostBack page or NOT). You need to add that if(!IsPostBack) condition around the code where you are performing the databinding for the dropdowns in your RowDataBound event.

Categories : C#

how to maintain scroll position on postback in Gridview / Repeater
You can use below link using jquery http://www.sergeyakopov.com/2010/11/easily-maintaining-scroll-position-in-gridview-using-jquery

Categories : C#

Why GridView.RowCreated event is fired when page postback
RowCreated is focused on parsing Gridview row's definition and creating the Gridview row's control structure, RowDataBound is focused on bind data to the row's controls created in the RowCreated. Also RowCreated is invoked automatically in both init and postback case, but RowDataBound is only invoke when the DataBind is called. Every time your grid has bind data, the RowCreated event will call each time. Have you bind gridview on page load? If this is your case, the RowCreated event will fire in every postback. To avoid this, check !IsPostback to control it and manage your gridview binding. In in most cases, everyone (including Microsoft) raccomend to use RowDataBound event instead of RowCreated. Hope to be helpful :)

Categories : Asp Net

Gridview returning empty even when there is data. I want to use data in the gridview to update another database
Per my comment above you may want to do something like: List<string> _OrderIds = new List<string>(); DataTable table = gvOrderLines.DataSource as DataTable; foreach (GridViewRow gvr in table.Rows) { Label myOrderIDLablel = (Label)gvr.FindControl("lblOrderID"); //find control since it is a template field _OrderIds.Add(myOrderIDLablel.Text); } I hope this get you headed in the right direction.

Categories : C#

display gridview data in another page or other gridview with row data in editable mode
You need to add RowCommand Event in GridView. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand"> <asp:LinkButton ID ="lnkEdit" runat ="server" CommandArgument='<%#Eval("Recordid")%>' CommandName ="cmdEdit" Text ='Edit'></asp:LinkButton> </asp:GridView> Here rocordid is the id of your record. In Page behind you need to write code. protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "cmdEdit") { string Recordid = Convert.ToString(e.CommandArgument.ToString()); Response.Redirect("EditPage.aspx?recordid="+Recordid ); } } On EditPage you can get recordid from the query string and can fetch the record form the datab

Categories : Asp Net

refresh Gridview using C#
You can set your DropDownList's AutoPostback attribute to true. I suggest you use also an UpdatePanel. You can read here to learn more about UpdatePanel.

Categories : C#

Refresh gridview with new databind
To auto refresh a grid view, you can do it in two ways, both of them has nothing to do with the div First way to to place it inside an update panel, and set the update panel to refresh at a specific interval in time: How to refresh an UpdatePanel control at a timed interval Second Way is to use jquery and ajax and update only specific rows. In this case no data binding will occur, it is more efficient and faster than the first way, but you will need to redesign your database and workflow so that you can always get the latest data that changed. This will suit you better if you have a real time system

Categories : Jquery

how to refresh GridView in $.ajax
You can't access web controls in in a static method directly. Instead of you can use other HTML tables plugins like DataTable. EDIT aspx page <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:Button ID="btnsearch" runat="server" Text="SEARCH" OnClick="btnsearch_Click" /> <asp:UpdatePanel ID="UpdatePanel2" runat="server"> <ContentTemplate> <asp:GridView ID="grdjobs" runat="server" AutoGenerateColumns="false" DataKeyNames="Id" AllowPaging="true" PageSize="10" OnPageIndexChanging="grdjobs_PageIndexChanging" GridLines="None" Width="950px" EmptyData

Categories : Asp Net

How to append a row to a gridview instead of a full refresh
This probably needs to be a comments but I want to show a line of code Container.DataItemIndex should be replaced with <%#DataBinder.Eval(Container, "DataItemIndex")%> and the function deleteRow need to come out. Your onclick should look like this onclick="deleteRow(myRow + <%#DataBinder.Eval(Container, "DataItemIndex")%>"

Categories : C#

Making code duplication to refresh the gridview in asp.net
You should provide a method that loads the data and databinds the GridView, for example DataBindGrid: private void DataBindGrid() { using(var con = new SqlConnection(University.GetConnectionString())) { con.Open(); string query = "select [ID],[Name],[Surname],[level] from StudentTable order by ID"; SqlCommand cmd = new SqlCommand(query, con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); studentLevel.DataSource = dt; studentLevel.DataBind(); } } Then you can call it from wherever you need. If you want to change something you have only one place to maintain which is less error-prone. Note that you should databind the GridView only if(!IsPostBack) if you use ViewState(d

Categories : Asp Net

UpdatePanel in EditItemTemplate of Gridview causing full page refresh
You need to specify AsyncPostBackTrigger inside the <Triggers> element for the UpdatePanel . I tried same and it was working. <asp:UpdatePanel ID="upSetSession" runat="server"> <ContentTemplate> <asp:DropDownList ID="ddlMyList" runat="server" onselectedindexchanged="ddlMyList_SelectedIndexChanged" AutoPostBack="true"> <asp:ListItem>One</asp:ListItem> <asp:ListItem>Two</asp:ListItem> <asp:ListItem>Three</asp:ListItem> </asp:DropDownList> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="ddlMyList"

Categories : Asp Net

Which control caused postback in apsx page when postback is triggered from JavaScript
Invoking the click event as you are guarantees that the save button will cause the postback. Is there a particular function you want to achieve by not putting your code in the server-side method (savebtn_Click)? Update If you would like to use the name button click for multiple select2 controls, try How to use __doPostBack(). If you just have the one select2, place your code in the button's event and use either of the following to extract the value: selectedValueFromRequest = Request["Select"] OR selectedValueFromControl = Select.SelectedValue

Categories : Javascript

Jscolor stops working after first postback of fresh deploy, but continues to work after postback of a reload
Finally I found a solution. It is so easy!!! I have to add before all input fields with class='color' (binding fileds to the jscolor) this code: <script>jscolor.init();</script>

Categories : Javascript

Gridview onRowCommand fired gridview no data
Problem in this line ID = gvWorkshop.DataKeys[grdrow.RowIndex]["workshopID"].ToString(); You have mention "grdrow" in place of "row". please change it to ID = gvWorkshop.DataKeys[row.RowIndex]["workshopID"].ToString();

Categories : C#

Data won't show on page when postback
Edit Alright, I am going to try to help you as best as possible and point a few things out along the way - Open your project in Visual Studio or your editor of choice and do a 'Find', search the entire project, and anywhere you see 'latestValue' used in your viewModels or views, or really anywhere besides inside of your Knockout Library, you need to delete it. If you need a value from a KO Observable or ObservableArray, use the getter function - if (memos._latestValue.length == 0) should be if (memos().length == 0) I know that I have answered a question for you before and recommended this, I went back and double-checked it to be true, but seriously you need to do this, you are bypassing Knockout's core functionality by using _latestValue. I checked a few of the ID observable

Categories : Knockout Js

DisplayFor is not keeping data in ViewModel on PostBack
Only values that are part of an input or other form control will be posted back to the client. DisplayFor is just meant for the model to display its data, nothing else. You have two options; use a hidden field so that the model is populated with the data each time, or fetch the value again. The former method would be fine if your data isn't sensitive because an end user can change the hidden value and repost your form. So for example a UnitPrice would NOT be something you'd want to ever get from the client as even in a hidden field a malicious user can modify the unit price. In that case you'd always want to reload the data yourself and repopulate the model. There's nothing wrong with that either; if the data isn't editable and you need to display it, you need to get it every time.

Categories : Asp Net Mvc

Is it possible for a server to treat a postback as not a postback?
Any asp:button click will cause a postback to the server because asp is a server side language so it has to talk to the server to execute the button click. If you want to do button clicks without talking to the server use something like javascript

Categories : C#

Fetching data from a webpage with asynchronous postback with javascript or c#
I would recommend using a tool like Fiddler to capture the entire requests that are caused by your manual actions, and then send them using WebClient. Also, That way you can capture the requests of WebClient and compare them with the original.

Categories : C#

Sending data from usercontrol to main page on postback
create a custom event in user control create a property in usercontrol fire the event when the button is clicked & set the property value access the property in the main page in user control's eventhandler

Categories : Asp Net

save state in postback for a data-bound control
Find the control from the repeater's Items, not on the repeater itseld. Try this: void AdverticRp_ItemCommand(object source, RepeaterCommandEventArgs e) { if(e.CommandName == "delete") { RepeaterItem item = e.Item; if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem) { FileUploader fu = item.FindControl("fu") as FileUploader; // do somthing here } } }

Categories : Asp Net

how to persist partial view model data during postback in asp.net mvc
Try searching first. This question has been asked many times before. Here is one way to do it: mvc partial view post Summary: wrap each partial in multiple form tags each with their own submit button. But this one seems more like what you're after: Post a form with multiple partial views Use editortemplates for this instead of partials. The issue you're having is that when your DepartmentName textbox isn't being named correctly for your controller to read it. Your POST would be EmployeeName=Prashant&DepartmentName=Phy therefore Department is null, hence the error.

Categories : Asp Net

Dynamically Created Controls losing data after postback
The dynamically generated control do not maintain state. You have to maintain it at your own. You can use some hidden field to keep the state of controls, which will be used on server side to extract the state. Asp.net uses hidden field to maintain the state between requests, you can see __VIEWSTATE in the source. In ASP.NET pages, the view state represents the state of the page when it was last processed on the server. It's used to build a call context and retain values across two successive requests for the same page. By default, the state is persisted on the client using a hidden field added to the page and is restored on the server before the page request is processed. The view state travels back and forth with the page itself, but does not represent or contain any info

Categories : C#

how to show search data after postback function call in asp.net
Here are some solution : 1- After every user search , Redirect user to page with parameter( like query string) and then on that page retrieve parameter and show appropriate result 2-Asp.net pages by default maintain page state by "View-state" , First make sure ViewState property of the page is True , Then make sure in page life cycle where you have rebind gridview 3-If there is situation in which #2 solution didn't work , There are another solution and that is saving page state in ViewState page explicitly Hope these help

Categories : Asp Net

update or refresh gridview in asp.net when there is any Insert,Update or Delete in the database
you can user SignalR for building a real time application. have a look at this link it have exactly what you want http://www.asp.net/signalr/overview/getting-started/tutorial-server-broadcast-with-aspnet-signalr

Categories : Asp Net

Listbox in dynamic web user controls lost data after postback
Your problem is that you are adding the new items in the DOM, but these changes will not necessarily be reflected in your ListBox after a page refresh or PostBack. I could suggest two solutions: 1) Add the elements in the ListBox through .net instead of using Javascript. but if you need a client side solution so that your page won't refresh everytime you add an item: 2) Add a .net HiddenField control. These controls have the advantage of being accessible easily from both Client Side and Server Side. You can add each item in both, the ListItem and the HiddenField (maybe comma separated) and on the server side you will use this HiddenField instead of your ListBox.

Categories : Vb.Net

Getting data back from composite control added to placeholder on postback
I asked this a long time ago, But I think this is how you should do it. Using a factory pattern for user controls. http://weblogs.asp.net/sfeldman/archive/2007/12/17/factory-pattern-for-user-controls.aspx

Categories : Asp Net

ASP.Net object reference error when writing data to xml file via Gridview Empty data template
The issue is when you have the xml file without 'po' node. You can move the node to a new method like: Private Function CreatePOSDataset() As DataSet Dim oDs As New DataSet() oDs.DataSetName = "newshipmentnotification" oDs.Tables.Add("pos") oDs.Tables("pos").Columns.Add("pos_Id") oDs.Tables("pos").Columns("pos_Id").ColumnMapping = MappingType.Hidden oDs.Tables.Add("po") oDs.Tables("po").Columns.Add("ponumberID") oDs.Tables("po").Columns.Add("pos_Id") oDs.Tables("po").Columns("pos_Id").ColumnMapping = MappingType.Hidden oDs.Tables("po").Columns.Add("ponumber") Dim pos_po As DataRelation = oDs.Relations.Add("pos_po", oDs.Tables("pos").Columns("pos_Id"), _ oDs.Tables("po").Columns("pos_Id"))

Categories : Asp Net

Export Gridview Data to Excel in ASP.NET Linq data bind
It's pretty easy to set up the excel export that will export only the gridview. This has been tested and will only export the gridview that appears on your given web page. For your C# code use the following: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class vxcel_export : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button2_Click(object sender, EventArgs e) { Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=file-name.xls"); Response.ContentType = "application/vnd.xlsx"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); Sys

Categories : Asp Net

Improve page rendering time having gridview, child gridview and grand child gridview on it
You are creating way too many grids. A grid is an expensive component. You could alter your user interface to allow users to select an Item and bind the inner grid only on selection. This ensures that rather than one grid per row or parent grid, you will have only one child grid displayed at a time.

Categories : C#

Slow get data from data gridview into SQL Server
A fast way to insert many records into an SQL Server's table is to use the SqlBulkCopy class. First you will need a function which will copy the content of your DataGridView into a DataTable. Private Function GetDataTable() As DataTable Dim DataTable1 As New DataTable Dim i1, i2, RowsCount1 As Integer For i1 = 0 To DataGridView1.Columns.Count - 1 DataTable1.Columns.Add(DataGridView1.Columns(i1).Name, DataGridView1.Columns(i1).ValueType) Next If DataGridView1.AllowUserToAddRows = True Then RowsCount1 = DataGridView1.Rows.Count - 1 Else RowsCount1 = DataGridView1.Rows.Count End If For i1 = 0 To RowsCount1 - 1 DataTable1.Rows.Add(DataTable1.NewRow) For i2 = 0 To DataGridView1.Columns.Count - 1 DataTabl

Categories : Vb.Net



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.