如何在ASP.NET中得到及时的价值? [英] How to get prompt value in ASP.NET?

查看:158
本文介绍了如何在ASP.NET中得到及时的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的,当用户输入提示框和$ P $文本psses确定按钮,提示框将发送回值字符串PRMT; ,如果他们取消了提示,它不会做任何事情。

What I want to do is when the user enters a text in the prompt box and presses the OK button, the prompt box will send back the value to string prmt; and if they cancelled the prompt, it will do nothing.

codeS:

string prmt; 
if(ren>=1)
{

    ClientScript.RegisterStartupScript(this.GetType(), "prompt", "prompt('Enter your message here.')", true);

//if(ok){}
//if(cancel){}

}

对不起,我的语法。

Sorry for my grammar.

推荐答案

有关这个问题,我能想到的会是AJAX最好的解决办法,但有一个另一种方式。在HTML文件中像这样创建一个隐藏字段:

For this problem, the best solution I can think of would be AJAX, but there is an another way. Create a hidden field in the HTML file like this:

<form id="theform" runat="server">
        <input type="hidden" id="hidValue" runat="server" />
</form>

现在,应该做的下一件事是一个JavaScript块添加到您的HTML文件。这个片段将得到及时的价值,并将其存储在我们已经之前创建的隐藏字段。像这样的东西可能会工作:

Now, the next thing that should be done is to add a JavaScript block to your HTML file. This snippet will get the prompt's value and store it in the hidden field that we had created before. Something like this will probably work:

<script type="text/javascript">
        function storeinput(value) {
            document.getElementById("<%=hidValue.ClientID%>").value = value;
        }
</script>

这创造了一个 storeinput 函数,调用时将隐藏字段的值设置为所提供的参数。我们需要做的下一件事就是与ASP.NET把它们绑在一起。
而不是

This has created a storeinput function, which when called will set the hidden field's value to the provided value argument. Next thing we need to do is to wire them together with the ASP.NET. Instead of

ClientScript.RegisterStartupScript(this.GetType(), "prompt", "prompt('Enter your message here.')", true);

做到这一点:

ClientScript.RegisterStartupScript(this.GetType(), "prompt", "var value = prompt('Enter your message here.'); storeinput(value);", true);

或类似的东西(我不是真的ASP.NET经历过,但我想这将正常工作)。之后你只是简单的用你喜欢的方式ASP.NET检查 hidValue 字段的值,你是好去。

Or something like that (I am not really experienced with ASP.NET, but I guess that will work fine). And after you just simple check the hidValue field's value using your favourite ASP.NET way and you are good to go.

这篇关于如何在ASP.NET中得到及时的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆