473,770 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3666
"=?Utf-8?B?d2lsbGlhbQ= =?=" <wi*****@discus sions.microsoft .com> confessed in
news:04******** *************** ***********@mic rosoft.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="javas cript">
function myJavaScriptFun ction() {
//do some stuff here
}
</script>

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

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

That help you any?
Jeppe Jespersen
jdj-jdj.dk
Nov 19 '05 #3
Jos
"william" <wi*****@discus sions.microsoft .com> wrote in message
news:04******** *************** ***********@mic rosoft.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="myHand ler();" >

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="gdMemPortfo lio" runat="server" Height="64px"
Width="1048px" AutoGenerateCol umns="False">
<Columns>
<asp:BoundColum n Visible="False" DataField="ast_ key"></asp:BoundColumn >
<asp:BoundColum n DataField="seg_ label" headerText="Seg ment"></asp:BoundColumn >
<asp:BoundColum n DataField="mana ger" HeaderText="Man ager"></asp:BoundColumn >
<asp:BoundColum n DataField="asse t" HeaderText="Ass et"></asp:BoundColumn >
<asp:BoundColum n DataField="tota l_units" HeaderText="Cur rent
Units/Shares"></asp:BoundColumn >
<asp:BoundColum n DataField="vest ed_units" HeaderText="Ves ted
Units/Shares"></asp:BoundColumn >
<asp:BoundColum n DataField="mark et_value" HeaderText="Cur rent Vested Market
Value"></asp:BoundColumn >
<asp:BoundColum n DataField="pend ing_sell_units" HeaderText="Pen ding Sells
Units/Shares"></asp:BoundColumn >
<asp:BoundColum n DataField="pend ing_buy_amount" HeaderText="Pen ding Buys
Amount"></asp:BoundColumn >
<asp:BoundColum n DataField="fee_ units" HeaderText="Fee Charged
Units/Shares"></asp:BoundColumn >
<asp:BoundColum n DataField="ava_ units" HeaderText="Ava ilable
Units/Shares"></asp:BoundColumn >
<asp:BoundColum n DataField="ava_ amount" HeaderText="Ava ilable
Amount"></asp:BoundColumn >
<asp:TemplateCo lumn HeaderText="Uni ts/Shares">
<ItemTemplate >
<asp:TextBox OnTextChanged=" RowChanged" id=txtUnitsSell runat="server"
Width="100px" Text='<%# DataBinder.Eval (Container, "DataItem.trx_u nits") %>'>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Amo unt">
<ItemTemplate >
<asp:TextBox OnTextChanged=" RowChanged" id=txtAmountSel l runat="server"
Width="100px" Text='<%# DataBinder.Eval (Container, "DataItem.trx_a mount") %>'>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Per centage">
<ItemTemplate >
<asp:TextBox OnTextChanged=" RowChanged" id=txtPctSell runat="server"
Width="100px" Text='<%# DataBinder.Eval (Container, "DataItem.trx_p ct") %>'>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="All ">
<ItemTemplate >
<asp:Button id="btnAllSell " runat="server" Width="33px"
Text="All"></asp:Button>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Spe cific Cell">
<ItemTemplate >
<asp:CheckBox id=chbcellSell runat="server" Width="10px" Height="8px"
Enabled='<%# DataBinder.Eval (Container, "DataItem.g ia") %>'>
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateCol umn>
</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:BoundColum n DataField="ava_ units" HeaderText="Ava ilable
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 "ItemComman d". Also, for starters, set the buttonType
on the column to "LinkButton ". Somehting like this:
<asp:ButtonColu mn ButtonType="Lin kButton" Text="Sell All"
CommandName="It emCommand" />

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.Fi ndControl("txtC opiedCompanyNam e"), TextBox).Text =
CType(e.Item.Fi ndControl("lblC ompanyName"), 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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2516
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 database the DataGrid is using as a data source. When the popup window is closed I want to refresh the main window -- i.e., cause a postback to happen. Is this possible?
10
4516
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 (basically have the data binding done in the If NOT IsPostBack Then statement). How come? How does this information get preserved? Which raises another question. Becuase I want to get away from the spaghetti code approach, I would like to create...
9
7514
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 the postback than I don't want to do a DataBind otherwise I do. I know __EVENTTARGET doesn't return this information. Is there anything else that does? Thanks, Joe
7
1316
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 event. When clicking on the button in this control i want to add the selected rows in the grid to another grid, which is on my second control. I do this by handling the Click event of the button in my page and add the values to arraylist in the...
3
2052
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 clientside. So I would like to do this on the server side. So when the client is resized AND "the mouse button is up!!" I need a postback with the new size of the client. How would I do this? Just taking the onresize event is not enough as this event...
2
20642
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 browser window when the button is clicked. I tried doing this in the RowCommand postback event by doing this in the event handler: Response.Write("<script>window.open('SomePage.aspx');</script>");
6
2270
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 take quite a while to evaluate. Consequently that page can take a while to open. These links are alert for users indicating that they need to perform some actions. If they click any of the links they will get redirected to the appropriate page....
11
4247
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. How I stop the buttons from posting back when they are clicked? Thanks
0
6190
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 to prevent users from being able to click twice. Everything is working great, except for one small detail. When my client-side validation fires, and is invalid, I see the red text that displays the error message, but the problem is that something is...
0
9617
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9453
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10254
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10099
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10036
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.