|
-
Jan 22nd, 2009, 01:00 PM
#1
Thread Starter
Hyperactive Member
[2008] Image button : OnClientClick
I have an Image Button with a OnClientClick that show a confirmation message.
I want to use a message that is in a resource file. How would I do that?
This does not work. My reference to the resource file is the message I see instead of having the keyvalue as message.
Code:
OnClientClick="return confirm('<%$ Resources:LacMessage, DeleteConfirmation %>');" />
-
Jan 22nd, 2009, 03:21 PM
#2
Re: [2008] Image button : OnClientClick
Call a method from your attribute:
OnClientClick="return confirmDelete();"
From your codebehind, use ClientScript.RegisterClientScriptBlock to write the javascript out to the page.
This method takes a string, so you need to generate the javascript string first.
Something like
Code:
string deleteConfirmValueFromResourceFile = Resources.MyResourceFile.DeleteString;
string resourceValue = resourceManager.GetString(key);
string confirmationJs = "function confirmDelete(){ return confirm('" + deleteConfirmValueFromResourceFile + "');}";
ClientScript.RegisterClientScriptBlock(...............)
Note the 'something like', implying that I typed this without an IDE, so you'll need to modify it according to your circumstances.
-
Jan 23rd, 2009, 09:54 AM
#3
Thread Starter
Hyperactive Member
Re: [2008] Image button : OnClientClick
hello mendhak.
I am new to ASP.NET, so it was the first time for me using ClientScript.RegistreClientScriptBlock ..
Below is the way I did it, could you tell me if is sounds correct to you or If I do not used it the proper way.
I put this code in the design source code for my Delete button:
Code:
OnClientClick="return confirmDelete();"
I put this code my FormLoad event.
Code:
Dim strConfirmDeleteMsg As String = Resources.LacMessage.DeleteConfirmation
Dim strJavaSConfirmDelete = "<SCRIPT LANGUAGE='JavaScript' TYPE='text/javascript'> function confirmDelete() { return confirm('" + strConfirmDeleteMsg + "');} </SCRIPT>"
ClientScript.RegisterClientScriptBlock(Me.GetType, "DeleteConfirmation", strJavaSConfirmDelete)
It works very well. I just wanted to confirm I used that feature correctly before getting a bad habit.
Thank you for your help.
DoumB.
-
Jan 23rd, 2009, 10:48 AM
#4
Thread Starter
Hyperactive Member
Re: [2008] Image button : OnClientClick
I just noticed that in the FormLoad, I had to put the code out of my IsPostBack condition, otherwise, the javascript code was disappearing.
So even if it is a PostBack, I have to execute the VB code again so the javascript still work.
-
Jan 24th, 2009, 06:21 PM
#5
Re: [2008] Image button : OnClientClick
Yes and yes.
Your code looks good, and I'm glad it's working for you.
And yes, the javascript needs to be written out to the page each time, it is not part of a control because you are writing it directly to a page rather than to a control, so it does not persist in viewstate.
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
|