|
-
Aug 3rd, 2009, 10:48 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] help needed in implement the concept using javascript
Hi,
Here is my code
Code:
<ItemTemplate>
<asp:Label runat="server" Width="80%" Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>' ID="lblName"></asp:Label>
<asp:LinkButton ID="btnDelete" runat="server" Text="Delete" OnClientClick="return Confirm(event, 'Confirm', 'Delete Page Layout', message, 'Delete');"></asp:LinkButton>
</ItemTemplate>
i have seprate javascript function called Confirm. So this code is working fine for me.
i have another requirement that i need to append the label text in this javascript function.
for example in this javascript function i am passing "Delete Page Layout" as message. so i need to append the label text with this message.
for example
if the label text is vbforums then my message should be "Delete Page Layout vbforums?". so please help me to append the label text in this javascript message parameter.
i have tried like this
Code:
<asp:LinkButton ID="btnDelete" runat="server" Text="Delete" OnClientClick="return Confirm(event, 'Confirm', 'Delete Page Layout + '<%# DataBinder.Eval(Container.DataItem, "Name") %>', message, 'Delete');"></asp:LinkButton>
but it is not working. and one important is this should be done in aspx side only. i should not go for code behind.so please help me to achieve this .k indly give me some sample to do this pease.
-
Aug 3rd, 2009, 04:13 PM
#2
Re: help needed in implement the concept using javascript
Why should you not go into the codebehind and what exactly makes this 'avoidance' so important? Or are you being lazy? That's the most common reason when someone wants to avoid the codebehind - they're simply lazy and that's right, I ain't afraid to say it 
If the code above isn't working for you, you should tell us what exactly is happening. Come on karth, you've been on these forums long enough to know the drill. My guess would be that your quotes and double quotes are not mixing right, but only your details can help confirm it.
-
Aug 3rd, 2009, 10:26 PM
#3
Thread Starter
Fanatic Member
Re: help needed in implement the concept using javascript
Hi mendhak,
the error i am getting is The server tag is not well formed.
code i used :
Code:
<asp:LinkButton ID="btnDelete" runat="server" Text="Delete" OnClientClick="return Confirm(event, 'Confirm', 'Delete Page Layout'+"<%# DataBinder.Eval(Container.DataItem, "WebPartCategoryName") %>",'message', 'Delete');" ></asp:LinkButton>
please help me in this friend
-
Aug 4th, 2009, 02:07 AM
#4
Re: help needed in implement the concept using javascript
Hey,
Can you not set this value on the Load Event of the page rather than in the aspx markup? It would be far easier, and a better way, to do this, rather than trying to create it using Server Side Tags in the aspx page.
Gary
-
Aug 4th, 2009, 02:10 AM
#5
Re: help needed in implement the concept using javascript
I have little or no experience with this but you can try
Code:
"return Confirm(event, 'Confirm', 'Delete Page Layout'+'<%# DataBinder.Eval(Container.DataItem, \"WebPartCategoryName\") %>','message', 'Delete');"
Or someone with more knowledge of this can help. I'm sure gep loves inline code.
-
Aug 4th, 2009, 02:11 AM
#6
Re: help needed in implement the concept using javascript
Hey,
I used to use inline code all the time, but after reading your article, I was converted 
Although, still been reading about the ASP.Net MVC Framework, and it seems to love inline code!!
Gary
-
Aug 4th, 2009, 03:31 AM
#7
Thread Starter
Fanatic Member
Re: help needed in implement the concept using javascript
Hi Mendhak and Gary thanks for the reply. actully i got the solution.
Code:
OnClientClick='<%# String.Format( "return Confirm(event,\"{0}\",\"{1}\",\"{2}\",\"{3}\");" , "Confirm", "Delete Page Layout ", "Are you sure you want to delete " + Eval("WebPartCategoryName") + " ?","Delete")%>'
this does my requirement.
mendhak,
i will try yours and will get back to you.
why i am afraid of doing this in server side is if you look the paramenters there is a parameter called event. so rest of the other parameters we can send it from code behind, but what about event ? thats why i tried to do this in line.
doubt:
can it be possible to pass the event parameter from code behind?
my script as follows:
Code:
window.Confirm = function(mozEvent, prompt, title, message, buttonName)
{
// some other code here
}
please any sugestions
-
Aug 4th, 2009, 03:34 AM
#8
Re: help needed in implement the concept using javascript
Hey,
What I was talking about was using the ItemDataBound event of the control that you are using to set the OnClientClick property of the LinkButton, rather than using a Server Side Tag in the ASPX page. That will still maintain the client side functionality that you are after, but it will prevent you having to "hack" the Server Side Tag to get it to work the way you want it.
Gary
-
Aug 4th, 2009, 03:45 AM
#9
Thread Starter
Fanatic Member
Re: help needed in implement the concept using javascript
hi Gary,
i understood what you are saying, my first try was using item databound event of the link button only. but that was failed. because i am not to send event. the red marked.
Code:
OnClientClick='<%# String.Format( "return Confirm(event,\"{0}\",\"{1}\",\"{2}\",\"{3}\");" , "Confirm", "Delete Page Layout ", "Are you sure you want to delete " + Eval("WebPartCategoryName") + " ?","Delete")%>'
this event will be checked in the javascript function. so that i hav tried using inline itself.
any pointers please
-
Aug 4th, 2009, 03:54 AM
#10
Re: help needed in implement the concept using javascript
Hey,
The OnClientClick event is just a string value that you can set in the ItemDataBound event:
http://msdn.microsoft.com/en-us/libr...ck(VS.80).aspx
So I don't see why you can't just do what you are doing by writing "event" into the string that you set as the OnClientClick property.
I could be missing something though.
Gary
-
Aug 4th, 2009, 04:09 AM
#11
Thread Starter
Fanatic Member
Re: help needed in implement the concept using javascript
thanks for the information sharing gary. cheers
-
Aug 4th, 2009, 04:10 AM
#12
Re: [RESOLVED] help needed in implement the concept using javascript
Not a problem at all.
Did you try the method that I suggested? Out of curiousity, did this work, or are you sticking with the String.Format in the Server Side Tag?
Gary
-
Aug 4th, 2009, 07:05 AM
#13
Re: [RESOLVED] help needed in implement the concept using javascript
The 'event' is something that the javascript will understand. It's like asking "If I write alert('hello'); from the codebehind, will javascript understand the alert()? Yes, it will. All you're doing is generating the javascript and writing it to the HTML source from the codebehind.
-
Aug 4th, 2009, 10:21 AM
#14
Thread Starter
Fanatic Member
Re: [RESOLVED] help needed in implement the concept using javascript
Gary,
i have tried with appending the JavaScript with link button in item databound, it is not firing the java script when i click the button. so i have used the string.format, because today i have release. so this requirement is very important and no time also .so no time to do R & D. so used string.format in the inline itself. but i will try this once i get time.
Mendhak,
you are right, i understood this can be written in server side. i will try this surely.
Thanks lot friends.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|