Calling code from Javascript

When I click the button, I call the JavaScript function. After getting the value, I need to do some things from the value obtained in the code. How do I call the code?

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 function call button is configured as follows:

<button class="doActionButton" id="btnSelectImage" runat="server" onclick="openWindow('../rcwksheet/popups/uploader.htm')">Select Image</button>

My desired code (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 the code from JavaScript?
  • Is there any way to use the onclick property of a button to go to JavaScript first and then to the code?
  • Run "onchange" code call from TxtInput.Value?
+3
source share
3 answers

Yes, there is a way.

firstly, you can use javascript to submit the form after your return value is set to TxtInput.

function openWindow(page) {
  var getval = window.showModalDialog(page);
  document.getElementById("<%= TxtInput.ClientID %>").value = getval; 
  document.forms[0].submit();
}

TxtInput .

protected void Page_Load(object sender, EventArgs e)
{
    if (Page.IsPostBack)
    {
        if (this.Input.Value != string.Empty)
        {
            this.Input.Value += "blah";
        }
    }
}

: ,

+1

-, asp: ScriptManager aspx, / - javascript, :

WebServiceClassName.MethodName(javascriptvariable, doSomethingOnSuccess)

:

http://msdn.microsoft.com/en-us/magazine/cc163499.aspx

0

__doPostBack.

function openWindow(page) {
  var getval = window.showModalDialog(page);
  document.getElementById("<%= TxtInput.ClientID %>").value = getval; 
__doPostBack('btnSelectImage', getval);
}

:

PageLoad:

if (Request.Form["__EVENTTARGET"] == "btnSelectImage")
{
    //get the argument passed
    string parameter = Request["__EVENTARGUMENT"];
    //fire event
    btnSaveImage_Click(this, new EventArgs());
}
0
source

All Articles