|
Hi all, Happy New Year
Can someone please help me with the following scenario. I do not like how the default setting is to have the select and delete button together in a grid view row so I am extending gridview (for other reasons) and am dynamically adding my own fields, select at 0, delete at columns.count - 1.
Whenever I add OnClientClick code to the delete button the button is just posting back and not firing a delete command.
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
ButtonField select = new ButtonField();
select.CommandName = "Select";
select.ButtonType = ButtonType.Image;
select.ImageUrl = Page.ClientScript.GetWebResourceUrl(GetType(), EDIT_ICON);
Columns.Insert(0, select);
ButtonField delete = new ButtonField();
delete.CommandName = "Delete";
delete.ButtonType = ButtonType.Image;
delete.ImageUrl = Page.ClientScript.GetWebResourceUrl(GetType(), DELETE_ICON);
Columns.Add(delete);
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (Page.IsPostBack == false)
{
foreach (GridViewRow row in Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
ImageButton select = row.Cells[0].Controls[0] as ImageButton;
select.ToolTip = "Modify";
select.AlternateText = "Modify";
select.CssClass = "select-button";
ImageButton delete = row.Cells[row.Cells.Count - 1].Controls[0] as ImageButton;
delete.ToolTip = "Delete";
delete.AlternateText = "Delete";
delete.CssClass = "delete-button";
}
}
}
}
Thanks,
Maurice
|
|
|
|
|
OK, I have worked out why, should have found it earlier.
The OnClientClick is being output like this when I add my own client click code:
onclick="return confirm('Are you sure you want to delete this item?\n\nClick OK to delete this item or Cancel to keep it.');javascript:__doPostBack('OrganicGridView1','Delete$0')"
So my new question is, what event do I need to hook to so I can output something like this. I could do it client side but I would rather not.
onclick="if(confirm('Are you sure you want to delete this item?\n\nClick OK to delete this item or Cancel to keep it.')) { javascript:__doPostBack('OrganicGridView1','Delete$0') }"
Thanks
Maurice
|
|
|
|
|
ok, I have tried everything I can think of and cannot do it server side. I have tried ButtonFields, TemplateFields, CommandFields and all offer different access to the button but it still renders it's own javascript that I cannot change.
So ... I have resolved it with client side code let the gridview to render it out.
If anyone requires the code, see below.
If anyone has a server side solution please let me know.
Thanks,
Maurice
Client Code:
function setupDeleteConfirmation() {
var imgs = document.getElementsByTagName('input');
for (var i in imgs) {
if (imgs[i].title == 'Delete' && imgs[i].className == 'delete-button') {
imgs[i].oldClick = imgs[i].onclick;
imgs[i].onclick = function() {
var answer = confirm('Are you sure you want to delete this item?\n\nClick OK to delete this item or Cancel to keep it.');
if (answer == true) { this.oldClick; }
return answer;
};
}
}
}
Server Code:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (DesignMode == false)
{
if (Page.ClientScript.IsClientScriptIncludeRegistered("_GridViewClicks") == false)
{
Page.ClientScript.RegisterClientScriptInclude("_GridViewClicks", Page.ClientScript.GetWebResourceUrl(GetType(), GRID_JS));
}
}
}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
writer.WriteLine("<script type="text/javascript"> // <![CDATA[");
writer.WriteLine(" setupDeleteConfirmation(); // ]]>");
writer.WriteLine("</script>");
}
|
|
|
|
|
Dear all
How can I publish my web pages (my website) using ftp program ????
Plz Answer this q as quickly as possible
Many thaaanks
|
|
|
|
|
ahlamasp wrote: Plz Answer this q as quickly as possible
Sorry for the delay, I answered as quickly as I could
only two letters away from being an asset
|
|
|
|
|
ahlamasp wrote: Plz Answer this q as quickly as possible
You're obviously mistaking this for a paid service.
ahlamasp wrote: How can I publish my web pages (my website) using ftp program ????
By getting a web host who lets you upload the pages via FTP. I know GoDaddy does. That's how I upload my changes to my website there.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Many thanks for you "Christian Graus"
|
|
|
|
|
i need to create inherit from gridview with extra properties and one column but in design time i can't see the column how i can do that
with my regards
Aloways go ahead
|
|
|
|
|
Hi all ,
How to check an email exist or not in asp.net.I know how to check the format but if there is no such email address exist,I need to redirect to page with bounce back message.Please give me code to check email exist or not.
Thanks a lot.
|
|
|
|
|
You didn't like the answers you received five days ago?
|
|
|
|
|
Oh, I see. You're retarded. I am sorry about that. Call one of your helpers, you know, the ones who change your diapers. Ask them to explain the answers you got last time, I'm sure they are used to speaking slowly enough that you can understand them. Perhaps you should refrain from posting here again, until you're able to understand plain English. Oh, and if you're being paid to write code, then you are an utter disgrace.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
can any body help me in this regard.
How can i put these facility like codeproject did.
Print and mail to friend options
Umesh
|
|
|
|
|
cooolguymca wrote: Print
Done by JS. window.print() should do. BTW, you can view the source of code project page and see how they implemented it.
cooolguymca wrote: mail to friend
Read about System.Net.MailMessage and System.Net.SmtpClient classes.
|
|
|
|
|
For sending mail use code
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
public class clsSendMail
{
private String SMTPServer = string.Empty;
public clsSendMail()
{
SMTPServer = "localhost";
}
public String getSMTPServerName()
{
return SMTPServer;
}
public bool SendMail(String strToUser, String strFromUser, String strSubject, String strMessage)
{
bool blnResult = true;
MailMessage myMail = new MailMessage();
SmtpClient objSMTP = new SmtpClient(SMTPServer);
myMail.To.Add(strToUser);
myMail.From = new MailAddress(strFromUser);
myMail.Subject = strSubject;
myMail.Body = strMessage;
myMail.IsBodyHtml = true;
try
{
objSMTP.Send(myMail);
blnResult = true;
}
catch
{
blnResult = false;
}
return blnResult;
}
}
|
|
|
|
|
I am using the FileUpload control to upload files from client's local HDD to the server
But the code always searches for the file path on the server side
e.g.
If the user tried to upload a file C:\1.txt from his machine, He gets an exception "Could not find file C:\1.txt"
But if there is a file with the same path on the server it works and upload the server file instead
How can work around that
foreach(Minute m in MyLife)
myExperience++;
|
|
|
|
|
Mohammed Gouda wrote: But the code always searches for the file path on the server side
Your code is broken. Post the code which you are using for upload.
|
|
|
|
|
Hey, Navaneeth,
Wishing You and Your Family A Very Happy and Prosperous New Year !!!
cheers,
Abhijit
|
|
|
|
|
Thanks and wishing you too. 4 hours to go!
|
|
|
|
|
N a v a n e e t h wrote: Thanks Smile and wishing you too.
Thanks Man !!!
N a v a n e e t h wrote: 4 hours to go!
Ya!!! But Still Hanging in Office
Hope tonight have a party !!!
Enjoy !!!
cheers,
Abhijit
|
|
|
|
|
What is the .NET Framework version ?
|
|
|
|
|
What is the .NET framework version ?
Marcello Turnbull
|
|
|
|
|
Thanks to all participants
I solved it
I had a server side method as follows
AddAttachment(string filePath)
{
FileStream fs = new FileStream(filePath, FileMode.Open);
}
To solve the problem, I changed the method to
AddAttachment(byte [] fileContents)
{
}
foreach(Minute m in MyLife)
myExperience++;
|
|
|
|
|
Hi i am Datta,
i have aspx containg Window User control .
This Window user control have a textbox and setter property to set text of textbox.
i embedded this User Control inside aspx and want to communicate aspx textbox with that textbox of user control via Javascript.
but i am failed to set value of textbox of User control.
I am Using .NET 2.0 VS 2005 and C# lang.
If any body knows solution
thanks in advance..
DaTtA
|
|
|
|
|
Please ignore
Cheers!!
Brij
|
|
|
|
|
Hi all,
I need to auto send email when some posted a new ticket/event in my project.Please help me to achieve.
Thanks a lot.
|
|
|
|