简体   繁体   中英

Passing arguements to Javascript function from aspnet markup

I want to pass an argument to a javascript function in the aspnet webform. The function will open a window through on onClientClick of a button control in a GridView. I wanted to do this from markup. I tried passing the arguement as below:-

 OnClientClick='<%# String.Format("javascript:return
 gdvPopup({0});", Eval("MailID").ToString)%>' 

MailID field is in Guid format.

When I build the page I get an error message "expected ')'".

The javascript function is as below:-

function gdvPopup(MailID) {
var newURL = 'LinkMails.aspx?Inmail_ID=' + inmailID;
window.showModalDialog('' + newURL +'', 'name'
,  'dialogWidth:255px;dialogHeight:250px');
}

I am using VS 2012

After trying different combinations, I changed over to adding an attribute to the button control during GrivView_DataRowBound event and it works fine.

But can someone point out as to what error am I committing here in the markup? Is there any better way around?

您忘记完成ToString方法的()

OnClientClick='<%# String.Format("javascript:return gdvPopup({0});", Eval("MailID").ToString())%>'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM