最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Creating a customized "YesNo" alert box in asp.net (javascript) - Part 2 - Stack Overflow

programmeradmin0浏览0评论

I am trying to create a customized messagebox using javascript but not getting too far.

    string txtConfirmMessage = "On " + DateTime.Now + ", ";
    txtConfirmMessage = txtConfirmMessage + sUserID;
    txtConfirmMessage = txtConfirmMessage + " added this record. Do you want to continue? ";
    btnSubmit.OnClientClick = @"return confirm('" + txtConfirmMessage + "' Do you want to continue);";  

I need to display a custom message involving the UserID, the date, and the value that the user has enetered. When I click the Submit button, the messagebox does not pop up.

Update:
I know this code is executed at the Page_Load event. However, is it possible to display in this alert box, a value that the user has selected (that action occurs after the page load event) ?

Any ideas to resolve this issue?

I am trying to create a customized messagebox using javascript but not getting too far.

    string txtConfirmMessage = "On " + DateTime.Now + ", ";
    txtConfirmMessage = txtConfirmMessage + sUserID;
    txtConfirmMessage = txtConfirmMessage + " added this record. Do you want to continue? ";
    btnSubmit.OnClientClick = @"return confirm('" + txtConfirmMessage + "' Do you want to continue);";  

I need to display a custom message involving the UserID, the date, and the value that the user has enetered. When I click the Submit button, the messagebox does not pop up.

Update:
I know this code is executed at the Page_Load event. However, is it possible to display in this alert box, a value that the user has selected (that action occurs after the page load event) ?

Any ideas to resolve this issue?

Share Improve this question edited Sep 30, 2010 at 17:06 user279521 asked Sep 30, 2010 at 16:47 user279521user279521 4,80721 gold badges80 silver badges111 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

The javascript that you have is not valid, as the "confirm" method taks a single parameter, but you are giving it two bits.

Try this modified version.

string messageFormat = "On {0}, {1} added this record.  Do you want to continue?";
string formattedMessage = string.format(messageFormat, DateTime.Now, sUserID);
btnSubmit.OnClientClick = "return confirm('" + formattedMessage + "');";

You just have an extra string after the one you're passing to confirm(), change it to this:

btnSubmit.OnClientClick = @"return confirm('" + txtConfirmMessage + "');";

About the update of the question, you could assign an OnClientClick event handler to the button as late as PreRender and the value will be persisted in the ViewState.

发布评论

评论列表(0)

  1. 暂无评论