0

I want to display data in the modal popup.

Here is what I have, a grid with a link button that has a onclientclick something like this: OnClientClick='showComfirm(this, <%# Eval("Message") %>); return false;'.

Then in the javascript,

function showConfirm(source, message){
     this._source = source; 
     document.getElementById('lblmessage').text=message; // not sure if this proper syntax though.
     this._popup = $find('mdlPopup');
     this._popup.show();     
 }

UPDATE

The javascript errors I was getting were due to the text which the varialble "message" contains. The varialbe contains plain English text such as a email message, with upper case, lower case letters, exclamation marks, commas, periods, appostrophies, double quotes, space, etc. So is there a workaround for this? Thanks, R.

3
  • I think technically you can do that. Seems like a poor choice if you are passing sensitive information between server and client. Could you explain what the goal is that might help
    – mattacular
    Dec 27, 2011 at 20:13
  • I'm short on space so the grid only displays date, sender, and subject of the message. When you click on the subject link the modal will display the actual message.
    – Risho
    Dec 27, 2011 at 20:23
  • except that I get an error of ill formed tag.
    – Risho
    Dec 27, 2011 at 20:24

2 Answers 2

1

Yes it is possible, just straighten out quotes and such and you should have it (you may need to add some quotes around the message for the string to actually concatenate and become a string in the javascript properly).

To debug any problems with it, just view source in your browser when you've rendered the control and make sure that the javascript produced by the line given is correct.

Example:

You want this:

OnClientClick='showComfirm(this, "Are you sure you want to do this?"); return false;'

and NOT this:

OnClientClick='showComfirm(this, Are you sure you want to do this?); return false;'

UPDATE

I was able to get this to work:

<asp:LinkButton ID="LinkButton1" runat="server" onclientclick='<%# "alert(\"" + Eval("Message") + "\");" %>' Text='<%# Eval("Message") %>'></asp:LinkButton>

of course, I'm using C#, the VB equivalent would be:

<asp:LinkButton ID="LinkButton1" runat="server" onclientclick='<%# "alert(""" + Eval("Message") + """);" %>' Text='<%# Eval("Message") %>'></asp:LinkButton>

If this still isn't working, try to debug the JavaScript using either IE & VS or FireFox & FireBug. Perhaps the error is in the function and not the call.

Note that LinkButton controls automatically create HRef code for postback, so right after my alert message, I get a post-back which doesn't interfere with my test, but it may with your real situation. Perhaps a simple < a > tag would work better for you than a LinkButton control.

If you STILL can't get this to run, can you please respond with the JavaScript error you are receiving?

1
  • Thank you for all your help, but it continues to error out. Only time it does't error if OnClientClick='showComfirm(this, "Test message"); return false;' - this however still won't display the message. I've set the document.getElementById("ct100_ContentPlaceHolder1_lblMessage").innerHtml = message; . If I add <%# Eval("Message") %> in any way enclosed with quotes, single or double or with plus (+) sign I get a javascript syntax error.
    – Risho
    Dec 27, 2011 at 20:59
0

Yes, like that.

OnClientClick='<%# "showComfirm(this, \"" + Eval("Message") + "\"); return false;" %>'

The <%# %> is not just displaying the data, it binds the data to the field, so if you use single quotes, only a bind expression can be inside.

5
  • Thaks for your post, this however gives a "undetermined string constant" error. (Message is a valid varialble with data)
    – Risho
    Dec 27, 2011 at 20:58
  • That's a JavaScript error. Show the markup that is generated. There may be quotes inside a message or something like that.
    – aikixd
    Dec 28, 2011 at 11:24
  • Here is how if is rendered in view source: <a onclick="showConfirm(this, &quot;Hello Everyone! I wanted to put out a reminder that our Elections are this coming Monday. It is very important that all show up for this meeting. So don&#39;t miss our Final Meeting of the year. Thanks! &quot; ; return false;" id="ctl00_ContentPlaceHolder1_fvEmailHist_ctl02_lbSubject" href="javascript:__doPostBack(&#39;ctl00$ContentPlaceHolder1$fvEmailHist$ctl02$lbSubject&#39;,&#39;&#39;)" style="display:inline-block;width:245px;">Elections</a>
    – Risho
    Dec 28, 2011 at 15:30
  • Also, there is another error "Expected ')'", but not sure where it wants it.
    – Risho
    Dec 28, 2011 at 15:31
  • Theres a semicolon that not need to be there. After "Thanks! &quot;"
    – aikixd
    Dec 30, 2011 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.