문제

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).

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top