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

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

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745503366a4630516.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信