I have 2 page.
When double click row data in first page will be go to second page.
second page is for update purpose.
when successful update in second page and i want back to first page, the data show not updated in first page but when refresh the data will show updated record.
How can i get the updated record show in first page without click refresh?
below is first page aspx code:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr style="cursor: hand;" onmouseover="this.style.backgroundColor='#E6F0FF'"
onmouseout="this.style.backgroundColor='#FFFFFF'"
onclick="javascript:window.location.href='V_Updated.aspx?mail=<%#Eval("mail") %>'">
<td class="line_table_td" style="text-align: center;"><%#Eval(" mail ")%> </td>
<td class="line_table_td" style="text-align: center;"><%#Eval(" remarks ")%> </td>
</tr>
</ItemTemplate>
</asp:Repeater>
second page aspx button back code:
<td class="btn_bg" onclick = "history.back();">Back</td>
Better to use AJAX for updating data, if it is suitable for your project. This way you do not have to use two different pages.
http://www.webblogsforyou.com/ajax-introduction-how-to-use-ajax-in-asp-net-with-example/
Thanks!
Don't go back using the browser history (e.g. using history.back()). Different browsers handle caching differently, so it's difficult to control if your page would get refreshed. Provide a proper link to the previous page instead.
Simply put a link in second page like below :
<a href="firstpage.aspx" > Back </a>
Related
I am using the following code for a "Back" Button:
<INPUT type="button" value="Button" onclick="window.history.back(); return true;">
But, on the Previous page I have two div elements. When the page loads it will show div1. The next time, when the button of div1 is clicked, div2 will show. On div2 I have a "Next" button. which redirects to the other page. I want code for a "Back" button, which will show div2 when Back is clicked. Also, If I use history.back() it will show div1.
HTML code
List all your liabilities as calculated on the day the debt was forgiven to
the debt was forgiven prior
NEXT
<div id="d2">
<table cellspacing="3">
<tr>
<td colspan="2" class="styleh">
<p>
<b>Part II. List the fair market value (FMV) of all your assets, calculated as of the
day prior to the debt being forgiven - this would be the "sell today, cash value."</b></p>
</td>
</tr>
<tr>
<td>
</td>
<td>
<button id="btncalc" onclick="return btncalc_onclick()">
Calculate</button>
<button id="Button2" runat="server">
BACK</button>
</td>
</tr>
</table>
</div>
Thank you in advance
Try it :
<INPUT type="button" value="Button" onClick="history.go(-1);return true;">
OR
You can also try Asp.net Wizard Control for your scenerio.You can handle NextButtonClick
PreviousButtonClick events through this control.
change return true; to return false;
I think you will have to maintain some state to accomplish this functionality...I would suggets you to use cookie for this..set cookie when you click second div and go to the next page (you would find lot of ways of setting cookie through javascript, Here is example) and when you go back to first page check this cookie and explicitly show the second div and immedietly clear that cookie so that it won't persist...this is the one way which came instantly in my mind...
If you want to remember what state the previous page was in, you'll have to use some sort of storage.
The methods I'm most familiar with is the session variable, but using it will require you to do the coding in the codebehind of the aspx page.
protected void url_onClick (object sender, EventArgs e) {
Session["state"] = "div2";
Response.Redirect("url_of_new_page");
}
Of course you'll have to create your page based on the state during Page_Load.
If you want do to it purely in javascript, you'll have to use cookies, which I can't explain unfortunately, but here's a link to w3schools.
I have the following table in an ascx user controll:
<tr runat="server" id="rowChangeSerNo">
<td colspan="2">
<table id="tblChangeSerNo" runat="server">
</table>
</td>
</tr>
<tr id="row" runat="server">
<td>
<asp:Button ID="btChangeSerNo" runat="server" Text="Update" OnClick="btChangeSerNo_onClick" />
</td>
</tr>
I create the tblChangeSerNo dynamically with text boxes prefilled with the current values in the db. The idea of the control is to allow the user to update the values of the DB with new values. The problem is that when the btChangeSerNo_onClick method is called:
The table is not rendered, since I do it on pre-render
Even if I rendered the table on Page_Load I could not access updated values of the user because they are lost.
How can I solve this problem?
The best practice way will be to use Grid control instead.
If you prefer to stick with your own code, follow those steps:
Store all the text boxes in global fields, e.g. public List<TextBox> m_tableTextboxes = new List<TextBox>(); and when creating add to that list.
Have the code creating the dynamic controls in the Page_Load but execute it only when not is PostBack: if (!Page.IsPostBack) { ... }
In the button click event, read the values from your global field.
Done something similar in the past, so the concept should work.
I'm learning C# and working on my first ASP.Net e-commerce website.
I have the following repeater:
<asp:Repeater ID="Cartridges" runat="server" OnItemCommand="Cartridges_ItemCommand">
<ItemTemplate>
<asp:LinkButton ID="buy" runat="server" CommandName="AddtoCart" CommandArgument=<%#Eval("cartID") %> Text="Buy"></asp:LinkButton>
</ItemTemplate>
However, when the code is rendered the repeater produces JavaScript to postback which is no good when populating a shopping cart if the user has JavaScript turned off!
<div class="wrap-cart">
<div class="cartbuy"><a id="ContentPlaceHolder1_Cartridges_buy_0" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Cartridges$ctl00$buy','')">Buy</a></div>
<div class="cartimg"><img src="pic/epson-comp-set50.jpg" alt="product" /></div>
<div class="carttext">
<p class="cartdesc"><span class="homeprinters">product</span></p>
<p class="cartprice">£x.xx</p>
</div>
All I want to do is to pass the cartID to a data table. Is there a way round it so JavaScript is not involved at all?
For completeness here's my code behind:
protected void Cartridges_ItemCommand(object source, RepeaterCommandEventArgs e)
{
cartidtest.Text = "added";
if (e.CommandName == "AddtoCart")
{
string varCartID = (e.CommandArgument).ToString();
//more code here
}
}
Sure, you can pass the selected ItemID via QueryString
First, Generate an anchor tag like this:
AddToCart
This may be accomplished in an ItemTemplate:
<a href='<%# "NextCheckoutStep.aspx?ItemID=" + Eval("ItemID").ToString() %>'>AddToCart</a>
Finally, in NextCheckoutStep.aspx, access:
Request.QueryString["ItemID"]
Notes
You can pass information back to the same page. Just replace NextCheckoutStep.aspx with CurrentCheckoutStep.aspx. You will just need to put some routing code into your Page Load (or init) handlers (with postback = false) to react to the various page states that are created by this method. Sometimes a state diagram is helpful in working with this design.
Make sure to 100% sanitize your QueryString-Reads, because malicious users will attempt to put nasty values in the query string.
You don't have to use the QueryString, you can also get by with the HTTP POST collection; however, you need to sanitize here too, because you can never trust inputs coming from the client.
I would have a link which includes the item id in a querystring. I would expect the user's cartId to be stored in a cookie or in a session variable.
<asp:Repeater ID="Cartridges" runat="server">
<ItemTemplate>
<p>Buy</p>
</ItemTemplate>
</asp:Repeater>
A LinkButton renders as a link that immediately forces a submit, so it needs javascript.
You will have to use a plain HyperLink to render a url like mypage.aspx?id=cartid.
You can use instead of LinkButton
Hi say of have a table of cars in my SQL database. That table has a column for the car make and a column called picture of type:
Picture(image, null)
I'm then displaying my cars in a repeater and so it might look like this:
<asp:Repeater id="carsRepeater" runat="server" DataSourceID="CarsDataSource>
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label id="carMakeLabel" runat="Server" Text='<%# Eval("Make") %>' />
</td>
<td>
Some how display a clickable image here
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</Footer>
</asp:Repeater>
What I'm wanting is in column two to get the picture of the car to display and make it so you can click on that picture and it will run a method in the code behind. Also I have this requirement where the picture click method mustn't require javascript to run.
Can someone please give me an idea of how I would go about this?
I'm currently thinking about putting the image somehow in a link but I'm not sure how to display the image. Maybe the asp:Image but that requires an ImageUrl.
Try image button, it displays an image, doesn't require javascript and you can run a method on click event from code behind
Write an HTTPHandler (say CarImage.ashx) and in that handler, given ID of the image return the binary data with ContentType of image/gif (or whatever). Render an image tag in the datagrid with src as CarImage.ashx?ImageID=xxxxx. The process is described many place including this one.
I have a simple repeater that looks like:
<asp:Repeater runat="server" ID="rptOptions" OnItemDataBound="rptOptions_ItemDataBound">
<HeaderTemplate>
<thead>
<tr>
<td class="GridHeader">Account</td>
<td class="GridHeader">Margin</td>
<td class="GridHeader">Symbol</td>
<td class="GridHeader">Usymbol</td>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tbody>
<tr runat="server" ID="trOption">
<td class="GridRow"><asp:Label runat="server" ID="lblOptionAccount"></asp:Label></td>
<td class="GridRow"><asp:Label runat="server" ID="lblOptionMargin"></asp:Label></td>
<td class="GridRow"><asp:Label runat="server" ID="lblOptionSymbol"></asp:Label></td>
<td class="GridRow"><asp:Label runat="server" ID="lblOptionUsymbol"></asp:Label></td>
</tr>
</tbody>
</ItemTemplate>
</asp:Repeater>
Now, in my code-behind I have an event which is fired that is supposed to add/insert a row into the database. After this happens, I re-grab the new list of options from the database and re-bind them to the repeater. This takes place inside an update panel so the list refreshes right away for the user.
protected void lbtnAddOptionSave_Click(object sender, EventArgs e)
{
SelectedOption = new Option()
{
Account = txtAddOptionAccountNumber.Text,
Margin = chkAddOptionMargin.Checked,
Symbol = txtAddOptionSymbol.Text,
Usymbol = txtAddOptionUsymbol.Text,
};
Presenter.OnAddOption(); // Insert new option into database
RefreshOptions(); // Re-get list of options, bind them to repeater
}
Now, what I would ~love~ to do, is use the jQuery ScrollTo plugin to scroll straight to the newly added row.
What would be the best way to call the ScrollTo() method in the jQuery plugin so I scroll to that particular row that was just added? Is there anyway I can mark my rows in my ItemTemplate so I can easily select an element to scroll to via jQuery?
Ideally, right after RefreshOptions() I would like to execute the ScrollTo function to scroll down to the new row.
If you know the client side Id of the row (which you can get), its relatively painless to simply call
$(document).scrollTo("#<row-id-here>", 800);
When you add the object to the database (or just after that), grab the id of the newly inserted object. Modify the repeater to include a Label with Visible="false" so that it doesn't get rendered to the client. Hook into the ItemDataBound event and check each label against the id you've grabbed. When you find the matching row, you can get the id of the row and then you'll be able to use for the scrolling parameter.
Note: Other data-bound controls have a DataKey property which could be used for the id of the object and make this a bit simpler. Not sure if you're tied to the Repeater at this point, but a GridView or ListView could be worth looking into.