By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,491 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,491 IT Pros & Developers. It's quick & easy.

how to prevent postback event for button in a grid

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
"=?Utf-8?B?d2lsbGlhbQ==?=" <wi*****@discussions.microsoft.com> confessed in
news:04**********************************@microsof t.com:
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?

--
Nov 19 '05 #2

P: n/a
> 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
Nov 19 '05 #3

P: n/a
Jos
"william" <wi*****@discussions.microsoft.com> wrote in message
news:04**********************************@microsof t.com...
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

Nov 19 '05 #4

P: n/a
Hey, at least we can all agree on how to do it. :-)))

Jeppe
Nov 19 '05 #5

P: n/a
Hi All,
Thanks.
I will try.

william

"Jeppe Dige Jespersen" wrote:
Hey, at least we can all agree on how to do it. :-)))

Jeppe

Nov 19 '05 #6

P: n/a
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
"Jeppe Dige Jespersen" wrote:
Hey, at least we can all agree on how to do it. :-)))

Jeppe

Nov 19 '05 #7

P: n/a
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
Nov 19 '05 #8

P: n/a
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

"Jeppe Dige Jespersen" wrote:
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

Nov 19 '05 #9

P: n/a
> <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
Nov 19 '05 #10

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

william

"Jeppe Dige Jespersen" wrote:
<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

Nov 19 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.