1

In one of my asp.net projects i have two asp textboxes which should run at server and update some values(in aspx.vb some calculation will occur). There is also a submit button of type input(html button) which on click calls a javascript(which is in .aspx page).

<asp:TextBox ID="TextBox1" runat="server" AutoPostBack=true   Width="38px"></asp:TextBox>

<asp:TextBox ID="TextBox2" runat="server" AutoPostBack=true   Width="33px"></asp:TextBox>

  <input type="button" id="22" value="Draw graph" OnClick="surface.plot1();"   />
  &nbsp;<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

Now the problem is that if i enter some values in TextBox1 and TextBox2 and directly click on the button then surface.plot1(); is not called for the first time.so i need to click the button once again to get surface.plot1(); fired. I know that it is because that i have entered value in TextBox2 and then directly clicked on the button,So AutoPostBack is done at first click of the button and when second time button is clicked the actual function gets called?.So how to avoid this so that at the first click of the button itself surface.plot1(); is called? Or is there any alternatives to achieve this? (But the TextBox2 autopost back should work otherwise everything will go wrong).

coder
  • 1,980
  • 3
  • 21
  • 32
IT researcher
  • 3,274
  • 17
  • 79
  • 143
  • By "update some values(in aspx.vb some calculation will occur)." you mean that you want to do some calculation when user changes something in these text boxes? – PM. Mar 15 '13 at 12:25
  • @PM. yes exactly. It is ok if those calculation occur anytime before the surface.plot1();(button onclick event) – IT researcher Mar 15 '13 at 12:27

1 Answers1

0

If it is OK for you to do these calculations any time before surface.plot1() then you can change your button to server side and on its click, do the calculations in Click function, once you are done with the calculations, call the javascript function surface.plot1() from your code behind as explained Here. And do remember to remove AutoPostBack="true" from your text boxes.

Community
  • 1
  • 1
PM.
  • 1,735
  • 1
  • 30
  • 38
  • but my javascript function is like Surface.prototype.plot1 = function(x, y, z){//code goes here//} so how can i call it from the code behind(aspx.vb) If i am calling it from aspx page then surface.plo1() works but how to call from code behind? (It is not like other function ex: function abc() ) – IT researcher Mar 15 '13 at 12:37
  • Procedure to call JavaScript function from vb.net code is explained [Here](http://stackoverflow.com/questions/9235017/asp-net-vb-call-javascript-function-from-code-behind) – PM. Mar 15 '13 at 12:41
  • plz see my last comment. i hav edited that while u r replying for me – IT researcher Mar 15 '13 at 12:43
  • The difference I could figure out is the input parameters, right? – PM. Mar 15 '13 at 12:44
  • Surface is an object so if i call the function from code behind then it does not work properly. In surface.plot there are so many functions which are not working properly. – IT researcher Mar 15 '13 at 14:08
  • Just a weird idea, you can call a simple javascript function like invokesurfacefunction(). And then from that function call your surface.plot1(). – PM. Mar 18 '13 at 05:34
  • I have already tried it,but it didn't work. Then what i did is again defined the object. It worked!! – IT researcher Mar 18 '13 at 07:16
  • Did you defined the object in your JavaScript function being called from code-behind? – PM. Mar 18 '13 at 09:38
  • Yes i defined the object in javascript being called from code behind – IT researcher Mar 18 '13 at 09:52