how to prevent postback event for button in a grid

G

Guest

Hi,
I have a datagrid, inside there is a templete item, it's button. I want to
do some thing when user click the button, but do not want the postback event
happens. How can I do it?
Thanks.

william
 
I

IPGrunt

Hi,
I have a datagrid, inside there is a templete item, it's button. I want to
do some thing when user click the button, but do not want the postback event
happens. How can I do it?
Thanks.

william

You gotta do something. Maybe you just want to use a straight HTML Control
and hook it's onclick event property to client-side javascript?

--
 
J

Jeppe Dige Jespersen

I have a datagrid, inside there is a templete item, it's button. I want to
do some thing when user click the button, but do not want the postback event
happens. How can I do it?

Well, since an ASP:Button is a server side control, there is no non-postback
functionality on it. If you click it, it will postback.

So you're limited to client side code. Only button control to handle
clientside code and not postback, is an HTML Button, which you'll find in
the HTML tab of your toolbox. Like this:

<script language="javascript">
function myJavaScriptFunction() {
//do some stuff here
}
</script>

.....and then in your HTML body somewhere....:

<input type="Button" value="Click me!" onclick="myJavaScriptFunction();">

That help you any?
Jeppe Jespersen
jdj-jdj.dk
 
J

Jos

william said:
Hi,
I have a datagrid, inside there is a templete item, it's button. I want to
do some thing when user click the button, but do not want the postback event
happens. How can I do it?

Make it a client-side button (no runat="server").
<input type="button" onclick="myHandler();" >

Jos
 
G

Guest

Hi Jeppe,
I tried to used HTML button, it does not fire postback event. But how can I
do some process on the datagrid from javascript function? Actually there is
textbox in the datagrid, when the button is clicked, I want to update the
textbox. Could you show me a sample?
Thanks.

william
 
J

Jeppe Dige Jespersen

I tried to used HTML button, it does not fire postback event. But how can I
do some process on the datagrid from javascript function? Actually there is
textbox in the datagrid, when the button is clicked, I want to update the
textbox. Could you show me a sample?

Hmmm....

In your first post, I understood that you didn't want the postback event.
Could you post the html from your aspx page, along with a description of the
exact functionality of your page. Will try to help, but no guarantees... :)

Jeppe
 
G

Guest

Hi Jeffe,
Thanks.
Here is the part of datagrid:(a little bit big)
<asp:DataGrid id="gdMemPortfolio" runat="server" Height="64px"
Width="1048px" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn Visible="False" DataField="ast_key"></asp:BoundColumn>
<asp:BoundColumn DataField="seg_label" headerText="Segment"></asp:BoundColumn>
<asp:BoundColumn DataField="manager" HeaderText="Manager"></asp:BoundColumn>
<asp:BoundColumn DataField="asset" HeaderText="Asset"></asp:BoundColumn>
<asp:BoundColumn DataField="total_units" HeaderText="Current
Units/Shares"></asp:BoundColumn>
<asp:BoundColumn DataField="vested_units" HeaderText="Vested
Units/Shares"></asp:BoundColumn>
<asp:BoundColumn DataField="market_value" HeaderText="Current Vested Market
Value"></asp:BoundColumn>
<asp:BoundColumn DataField="pending_sell_units" HeaderText="Pending Sells
Units/Shares"></asp:BoundColumn>
<asp:BoundColumn DataField="pending_buy_amount" HeaderText="Pending Buys
Amount"></asp:BoundColumn>
<asp:BoundColumn DataField="fee_units" HeaderText="Fee Charged
Units/Shares"></asp:BoundColumn>
<asp:BoundColumn DataField="ava_units" HeaderText="Available
Units/Shares"></asp:BoundColumn>
<asp:BoundColumn DataField="ava_amount" HeaderText="Available
Amount"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Units/Shares">
<ItemTemplate>
<asp:TextBox OnTextChanged="RowChanged" id=txtUnitsSell runat="server"
Width="100px" Text='<%# DataBinder.Eval(Container, "DataItem.trx_units") %>'>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Amount">
<ItemTemplate>
<asp:TextBox OnTextChanged="RowChanged" id=txtAmountSell runat="server"
Width="100px" Text='<%# DataBinder.Eval(Container, "DataItem.trx_amount") %>'>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Percentage">
<ItemTemplate>
<asp:TextBox OnTextChanged="RowChanged" id=txtPctSell runat="server"
Width="100px" Text='<%# DataBinder.Eval(Container, "DataItem.trx_pct") %>'>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="All">
<ItemTemplate>
<asp:Button id="btnAllSell" runat="server" Width="33px"
Text="All"></asp:Button>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Specific Cell">
<ItemTemplate>
<asp:CheckBox id=chbcellSell runat="server" Width="10px" Height="8px"
Enabled='<%# DataBinder.Eval(Container, "DataItem.gia") %>'>
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid></P>

what I want to do is when btnAllSell button is clicked, get data from
BoundColumn DataField="ava_units", fill it into txtUnitsSell textbox.

william
 
J

Jeppe Dige Jespersen

<asp:BoundColumn DataField="ava_units" HeaderText="Available
Units/Shares"></asp:BoundColumn>

what I want to do is when btnAllSell button is clicked, get data from
BoundColumn DataField="ava_units", fill it into txtUnitsSell textbox.

Me thinks me sees the light. :)

First of all I would change the btnAllSell to a buttoncolumn, and set the
columns commandName to "ItemCommand". Also, for starters, set the buttonType
on the column to "LinkButton". Somehting like this:
<asp:ButtonColumn ButtonType="LinkButton" Text="Sell All"
CommandName="ItemCommand" />

Then, in the Datagrids ItemCommand event, i would do something like the
following. Note that my column names are different than yours, so don't
copy-paste too much :) Anyways, like this:
CType(e.Item.FindControl("txtCopiedCompanyName"), TextBox).Text =
CType(e.Item.FindControl("lblCompanyName"), Label).Text

That should move the value. However, to retain copied values for more than
one field through multiple "copy" clicks, you would probably have to push
the copied field into your dataset or database. Try it out. Hope it helps
you out....

Jeppe Jespersen
 
G

Guest

Hi Jeppe,
Thanks.
Your approach works fine, but it causes postback event. Any idea how can I
do it without postback event?

william
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top