473,386 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how to prevent postback event for button in a grid

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
10 3628
"=?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
> 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
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
Hey, at least we can all agree on how to do it. :-)))

Jeppe
Nov 19 '05 #5
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
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
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
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
> <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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jay | last post by:
I have a situation where the user clicks on a button in a DataGrid to launch a popup window via javascript. In the popup window the user does some things that result in changes to the underlying...
10
by: Krista Lemieux | last post by:
I'm new to ASP.NET and I'm not use to the way things are handled with this technology. I've been told that when I have a control, I should only bind the data to it once, and not on each post back...
9
by: Joe | last post by:
I have a DataGrid with a templated column that displays ImageButtons. I need to know if one of these buttons caused the postback or just another button on the form. If one of these buttons caused...
7
by: Michael Groeger | last post by:
Hi all, I have designed user controls. One search control where I can search for items in the database and show them in a grid. This control also has a button which simply exposes it's click...
3
by: B G | last post by:
I have a grid, which unfortunately does not allow me to set its width to 100%. I need to specify the pixels. But as the grid is build up from many parts, I am unable to set the width on the...
2
by: Rob Roberts | last post by:
Is there any way to prevent a ButtonField in a GridView from doing a postback when clicked? I want to use my own onclick handler to call window.open('SomePage.aspx') to display a page in a new...
6
by: Terry Holland | last post by:
I have an asp page that contains a user control. This control is a panel containing a number of link buttons that get displayed if certain conditions in the db are met and these conditions can...
11
by: bill | last post by:
I dynamically create buttons and associate them with an event using AddHandler. I want all the button events to fire at one time, when the page is posted, instead of when each button is clicked....
0
by: josephkorn | last post by:
Hi all. I have a problem in my website in trying to prevent a user from double submitting the form. I am calling a subroutine from my page_load event that passes in the commandbutton that I want...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.