调用code隐藏在Javascript [英] Calling Code-behind from Javascript
问题描述
在一个按钮的点击,我所说的JavaScript函数。所获得的价值后,我需要从$ C $获得C-背后的价值进行了一些东西。我应该怎么称呼code-后面?
我的aspx:
函数的openWindow(页){
VAR GETVAL = window.showModalDialog(页);
的document.getElementById(<%= TxtInput.ClientID%GT;)。值= GETVAL;
//这之后,我需要从$ C $执行的东西上传(TxtInput.value)到数据库中C-背后
}
的按钮调用的功能被设置在方式如下:
<按钮类=doActionButtonID =btnSelectImage=服务器的onclick =的openWindow('../ rcwksheet /弹出窗口/ uploader.htm')&GT ;选择图片< /按钮>
我的背后所需code(VB):
公用Sub btnSaveImage_Click(BYVAL发件人为System.Object的,BYVAL E上System.EventArgs)把手btnSelectImage.ServerClick
昏暗INPUTFILE作为字符串= Me.TxtInput.Value
//做更多的东西在这里
结束小组
所以:
- 有没有办法从JavaScript的? 调用C-背后$ C $
- 我可以以某种方式使用一个按钮的onclick属性先去一个JavaScript,然后到code-后面?
- 引发code-背后叫的onchange的TxtInput.Value的?
是的,有一种方式。
首先,你可以使用JavaScript的返回值被 TxtInput
设置后,提交表单。
函数的openWindow(页){
VAR GETVAL = window.showModalDialog(页);
的document.getElementById(<%= TxtInput.ClientID%GT;)。值= GETVAL;
document.forms [0] .submit();
}
然后在code的背后,你可以处理的 TxtInput
页面加载事件的价值。
保护无效的Page_Load(对象发件人,EventArgs的发送)
{
如果(Page.IsPostBack)
{
如果(this.Input.Value!=的String.Empty)
{
this.Input.Value + =嗒嗒;
}
}
}
请注意:您可能需要<一个href=\"http://stackoverflow.com/questions/7319691/identifying-control-that-caused-postback\">Identifying控制造成回发
On the click of a button, I call a JavaScript function. After getting the value, I need to perform some stuff from the value obtained in the code-behind. How should I call code-behind?
My aspx:
function openWindow(page) {
var getval = window.showModalDialog(page);
document.getElementById("<%= TxtInput.ClientID %>").value = getval;
//After this I need to perform stuff 'Upload(TxtInput.value)' into database from the code-behind
}
The button calling the function is set up in the following manner:
<button class="doActionButton" id="btnSelectImage" runat="server" onclick="openWindow('../rcwksheet/popups/uploader.htm')">Select Image</button>
My desired code behind (VB):
Public Sub btnSaveImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectImage.ServerClick
Dim inputFile As String = Me.TxtInput.Value
//do more stuff here
End Sub
So:
- Is there a way to call code-behind from the JavaScript?
- Can I somehow use the "onclick" property of a button to first go to a JavaScript and then to the code-behind?
- Trigger a code-behind call "onchange" of the TxtInput.Value?
yes there is a way.
first, you can use javascript to submit the form after your return value is set in TxtInput
.
function openWindow(page) {
var getval = window.showModalDialog(page);
document.getElementById("<%= TxtInput.ClientID %>").value = getval;
document.forms[0].submit();
}
then in your code behind, you can handle TxtInput
's value in page load event.
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
if (this.Input.Value != string.Empty)
{
this.Input.Value += "blah";
}
}
}
note: you may need Identifying control that caused postback
这篇关于调用code隐藏在Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!