 |
|
 |
Hi Guys,
Ive been trying to add in this code for textbox attribute. When you click on edit, textbox will appear. I want to filter out certain characters in the textbox. When I clicked "EDIT", I traced the code & it works fine after the onload(). Do 'onchange', 'onkeypress' & 'onkeyup' work differently from 'onclick'. Please help. Thank you. Here's my javascript code.
Javscript Section:
function SetTextBox()
{
if (document.forms[0] != null)
{
for(i=0;i<document.forms[0].elements.length;i++)>
{
var x = document.forms[0].elements[i];
if(x !=null && x.name !=null && x.name.indexOf("ConfigDataGrid")== 0)
{
if(x.type=='text')
{
x.onchange = filterNumeric(x);
x.onkeypress = filterNumeric(x);
x.onkeyup = filterNumeric(x);
}
continue;
}
}
}
}
function filterNumeric(mobileNo)
{
if(mobileNo.value.length>0)
{
mobileNo.value = mobileNo.value.replace(/[^0-9]/g, '')
}
}
HTML Section:
<body class="pagedimension" önload="SetTextBox()">
<form method="post" runat="server">
<asp:datagrid id="QueueConfigDataGrid" runat="server" borderstyle="Solid" backcolor="#EEEEEE" cellpadding="4" allowsorting="True" oneditcommand="QueueConfigDataGrid_Edit" xmlns:asp="#unknown">
OnCancelCommand="QueueConfigDataGrid_Cancel" OnUpdateCommand="QueueConfigDataGrid_Update" OnItemCreated="QueueConfigDataGrid_ItemCreated" AutoGenerateColumns="False" CssClass="text" BorderColor="Silver" BorderWidth="1px" >
<selecteditemstyle forecolor="White" backcolor="#000099"></selecteditemstyle>
<headerstyle font-bold="True" forecolor="DarkBlue" backcolor="#EEEEEE"></headerstyle>
<asp:boundcolumn datafield="ID" readonly="True" headertext="ID">
<asp:boundcolumn datafield="ConnectionID" readonly="True" headertext="ConnectionID">
<asp:boundcolumn datafield="Server" readonly="True" headertext="Server">
<asp:boundcolumn datafield="QueueName" readonly="True" headertext="QueueName">
<asp:boundcolumn datafield="QueueType" readonly="True" headertext="QueueType">
<asp:boundcolumn datafield="QueuePause" headertext="QueuePause">
<asp:boundcolumn datafield="Status" readonly="True" headertext="Status">
<asp:editcommandcolumn updatetext="Update" canceltext="Cancel" edittext="Edit">
mk77 </form></body>
|
|
|
|
 |
|
 |
Hi
Akash
i tried your code given in this page.it displays Datagid but not showing messagebox and not performing any delete operations in datagrid i m new in asp.net
please can anyone help me
pratik
|
|
|
|
 |
|
 |
Hi,
how can i show the delete button for the particular rows in the grid view means i want to show the delete button for the rows which has been selected and not for those which are not selected
|
|
|
|
 |
|
 |
just add OnClientClick="return confirm('Are you sure you want to delete this?') in button tag and it will do all the job.
|
|
|
|
 |
|
 |
If you see clearly, ASP.NET 1.1 did not have OnClientClick, and this article was written for .NET 1.1 and not for 2.0, MS realized its value in 2.0
Programming is fun.
-Akash Kava
|
|
|
|
 |
|
 |
can some post the changes required to pull off this neat feature with a hyperlink column in the navigateurl I'm guessing?
thanks!
|
|
|
|
 |
|
 |
As you can see above, the name attribute of button starts with "TestGrid:". So we can use this as a guide, and search all form elements and attach event of onclick in client browser, making the server free from any code execution.
You seem to have glazed over something very important here in an instructional article. You should say how to add the onclick event to each of these delete button form elements.
|
|
|
|
 |
|
 |
I am getting this error when i am using your code (old way).
i am getting the error on this line.
my button is on the fourth column in the grid.
Button btn = (Button)e.Item.Cells[4].Controls[0];
is there any way out.
rupesh rajagopalan
|
|
|
|
 |
|
|
 |
|
 |
Did anyone have an idea of some simple code which works with Link Buttons? The standard DataGrid link buttons don't seem to have a name when they're rendered so we can't use the x.name property to find the object.
cheers,
Tim..
|
|
|
|
 |
|
 |
man i didnt used to share or write notes...
but ur pretty solution pushed me so hard...i just wana thank u and thank the person who share his knowledge with us...thx alot guys..
i hope u know how beautiful is islam
|
|
|
|
 |
|
 |
All good solutions above. I've done it the way below also. This worked well for using an image for the button. JScript code is a little simpler.
-- JScript --<script language="javascript">
<!--
function OnDeleteItem()
{
return window.confirm("Delete this item?");
}
//-->
</script>-- HTML --<asp:datagrid id="DataGrid1" runat="server" ...>
<Columns>
...
<asp:ButtonColumn Text="<img src=delete.gif border=0
align=absmiddle alt='Delete this item' onclick='OnDeleteItem()'>"
CommandName="Delete"></asp:ButtonColumn>
...
</Columns>
</asp:datagrid> Hope this helps.
Jonathan Craig
mcw-tech.com
|
|
|
|
 |
|
 |
Hi,
When you say "Just add the following script ......." where do you want to add the script?
Pantherot
|
|
|
|
 |
|
 |
hi i m unable to see the grid when try to run the prog i did it exactly like u show in ur ex. i m new to asp pl. help
|
|
|
|
 |
|
 |
You claim this technique is much more efficient than using the grid's ItemCreated event. Do you have any performance figures to back this up?
Performance is a very important part of programming but it needs to be balanced with other aspects such as complexity, debuggability (sic), and maintainability. On a simple web page, like in your example, wiring up javascript functions to the delete buttons onclick event is a very interesting approach. But on more complex web forms with lots of drop downs, buttons, menus and other UI elements this could become difficult to manage.
Nice article and nice idea. Thanks.
|
|
|
|
 |
|
 |
Right, explanation is here,
ItemCreated event executes on server side, imagin server serving 100 requests in a second and your datagrid populates for 20 items on each page, so total execution of time on server is 2000 times on server. Where else writing this javascript executes this code at client side which saves your server time. Whereelse individual browser's javascript execution doesnt count any load on server.
Benefit of javascript is to execute much of possible code of validation on client browser to save server's processing time.
- Akash Kava
Programming is fun.
-Akash Kava
|
|
|
|
 |
|
 |
I can imagine a lot of things, for example I can imagine improving server performance by abandoning the bandwidth hogging HTTP protocol and HTML syntax and going back to programming TN3270 terminals.
All I was asking is if you have some real performance numbers; page hits per second, CPU usage, all of that good stuff. Server performance isn’t the only consideration when designing a computer system.
|
|
|
|
 |
|
 |
Dear all I am providing here is some small advice, not a consulting service , such performance numbers takes long time to calculate and it should be service, something returned in terms of benefits for our company who do research and development, we have such product called jspisapi and on website www.jspisapi.com you will find how we claim and we improve server performance by using such plugin.
Not only this, we are coming with entire new web development environment similar to ASP.NET for other languages and platform independent, where we will improve all these features !!! Wait at NeuroSpeech for headline next month for release of this software.
Programming is fun.
-Akash Kava
|
|
|
|
 |
|
 |
i have tested my datagrid delete confirmation with your code but the performance really slow, slower that i normally use datagrid's itemdatabound event, that always makes my internet explorer browser not response.
but anyway, this is a helpful article for testing.
thanks.
happy programming!
|
|
|
|
 |
|
 |
We do this to accomplish the same prompt: <asp:Button ID="DeleteBtn" Text="Delete" runat="server" CssClass="Delete" OnPreRender="AssignDeleteVerifier"/> void AssignDeleteVerifier( object source, EventArgs e ) { Button btnDelete = (Button)source; string id = btnDelete.ClientID.Replace( "_", "" ); string js = "<" + "script language=Javascript>var " + id + "del=0;<" + "/" + "script>"; Page.RegisterClientScriptBlock( id + "definebutton", js ); Page.RegisterOnSubmitStatement( id + "OnSubmit", "if(" + id + "del == 1) {" + id + "del=0; return confirm('Are you sure you want to delete this item?');}"); btnDelete.Attributes.Add( "OnClick", "javascript:" + id + "del=1;"); } You can adjust the code a little to accommodate ImageButton too. We have found that the technique doesn't work too well with LinkButtons though... -- Brady P. Merkel bpmerkel@bryantdesign.com www.bryantdesign.com
|
|
|
|
 |
|
 |
Yes good solution ,but little bit of modified script of javascript in my code can also extend same for LinkButtons
Programming is fun.
-Akash Kava
|
|
|
|
 |
|
 |
You can make it even easier put the following js in your head section <!-- Client Side JavaScript --> <script language="javascript"> <!-- function ondeleteclick() { return confirm("Are you sure you want to delete this?") { function load() { for(i=0; i<document.all.length; i++) { var x = document.all.item(i) ; if(x!=null && x.name !=null && x.name.indexOf("dgName")==0) { if(x.name.indexOf("Delete")>0) { x.onclick = ondeleteclick ; } continue; } } } //--> </script> then ensure that you define the onload method in your body tag <body ... onload="load();" > and then in you datagrid <asp:datagrid id="dgName" ...> ... <ItemTemplate> <asp:imagebutton Runat="server" ImageUrl='<%#Page.ResolveUrl("~/images/icons/icon-delete.gif")%>' AlternateText="Delete" CommandName="Delete" CausesValidation="False" ID="Delete"> </asp:imagebutton> </ItemTemplate>
|
|
|
|
 |
|
 |
Thanks for posting this solution. It was just what I was looking for.
Just one thing.
Change:
btnDelete.Attributes.Add( "onclick", "javascript" + id + "del=1;");
To:
btnDelete.Attributes.Add( "onclick", "javascript:" + id + "del=1;");
Doesn't work without the : (colon)
Thanks again for posting.
|
|
|
|
 |
|
 |
You havnt actually changed anything...There is no : (colon)!!!
|
|
|
|
 |
|
 |
Interesting...
When I posted this comment, I was 100% sure it had the colon, looks like The CodeProject posting engine strips the colon from the line, as follows:
From:
btnDelete.Attributes.Add( "onclick", "javascript :" + id + "del=1;");
[note the space between "javascript" and ":"]
To:
btnDelete.Attributes.Add( "onclick", "javascript" + id + "del=1;");
if there is a colon after the word "Javascript", the engine takes it out.. Guess thats a security feature, so that malicious scripts won't run.
So, you are correct in your posting of the solution, but CodeProject made it incorrect.
|
|
|
|
 |