Link to home
Start Free TrialLog in
Avatar of allanmark
allanmark

asked on

How to manipulate the __doPostBack JavaScript function

F=Greetings all

I am trying to manipulate the JavaScript PostBack, in order to set a field value. My problem lies in the __doPostback call, in the JavaScript, as when I remove that line, things run as supposed to.

Suggestions?


In advance, thanks!
<SCRIPT LANGUAGE="JavaScript">    
function DoPostBack()
{   document.getElementById("HiddenField1").value = "ABCDE"
    __doPostBack(\'ListBox1\',\'\')', 0);
   alert("Hello 1"); 
}            
  
</SCRIPT>            
 
<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True" 
    Style="z-index: 100; left: 102px; position: absolute; top: 28px">
            <asp:ListItem>aaaaa</asp:ListItem>
            <asp:ListItem>bbbb</asp:ListItem>
            <asp:ListItem>cccc</asp:ListItem>
            <asp:ListItem>dddddd</asp:ListItem>
        </asp:ListBox>
        <asp:HiddenField ID="HiddenField1" runat="server" />
 
protected void Page_Load(object sender, EventArgs e)
    {
        ListBox1.Attributes.Add("onchange", "DoPostBack();");
 
        if (!Page.IsPostBack)
            HiddenField1.Value = "";  // Clear the field.
 
        Label1.Text = HiddenField1.Value;
 
    }

Open in new window

Avatar of Göran Andersson
Göran Andersson
Flag of Sweden image

Change

__doPostBack(\'ListBox1\',\'\')', 0);


to

__doPostBack('ListBox1','')', 0);
ASKER CERTIFIED SOLUTION
Avatar of Göran Andersson
Göran Andersson
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of allanmark
allanmark

ASKER

As always  -prompt and precise - thankyou, very much!!!