• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 966
  • Last Modified:

__doPostBack problem for login

I need to do some client-side validation and calculation before submitting a form, while still being able to benefit from the .NET-functionality. Therefore I tried to use the __doPostBack in order to first do my client-side calculations before triggering a .NET-button. But something is wrong...

This is a simplified code:
<form>
   <asp:textbox id="text1" enabled="false" runat="server" />
   <asp:textbox id="myText" enabled="true" CssClass="hidden" runat="server" />
   <asp:button id="btn1" OnClientClick="this.form.myText.Value = this.form.text.Value; __doPostBack('btn3','');" runat="server" Text="Click me" />
   <asp:button id="btn2" OnClick="myNetFunction" runat="server" Text="not visible" CssClass="hidden" />
</form>

The CssClass "hidden" is basically just a display:none to make it not visible, but still visible to use.

Ok, normally when I submit a valid form I get a confirmation message, and if the submitted form is invalid I get an error message. When I push the btn1 now it only processes some data, before refreshing the page and presenting me with a form (which includes the text in text1)... no response at all.

Do you know what I have done wrong?
0
wahooo
Asked:
wahooo
2 Solutions
 
royendCommented:
You need to understand the concepts of the __doPostBack: It doesn't invoke a button click, it only submits the form - which causes your page to refresh without the myNetFunction being run.

One solution might be:
protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
            myNetFunction(sender, e);
    }

which at least will go through your function when the form is being submitted.
0
 
Kiran Paul VJComputer EngineerCommented:
try this

<form>
   <asp:textbox id="text1" enabled="false" runat="server" />
   <asp:textbox id="myText" enabled="true" CssClass="hidden" runat="server" />
   <asp:button id="btn1" OnClientClick="javascript:function() {
this.form.myText.Value = this.form.text.Value;

var result = ValidationFunction();

if(result)
 __doPostBack('btn3','');
else
alert("Validation failed");

}"
runat="server" Text="Click me" />
   <asp:button id="btn2" OnClick="myNetFunction" runat="server" Text="not visible" CssClass="hidden" />
</form>

and in the head tag

<script language="javascript">
function ValidationFunction()
{
      if( Vaildation  Sucess)
        return 1;
      else // validation fails
        return 0;
}
</script>
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now