Solved

Autopostback=True not working in Visual Web Developer

Posted on 2006-07-06
14
431 Views
Last Modified: 2013-11-19
I am working with Visual Web Developer.  I am new to web development but have previous experience in Access and VB.

I am having problems getting the autopostback to work properly.  

Example:  I create a drop-down.  The autopostback property on the drop-down is set to true.  I select a value from the drop-down.  I want the value selected in the drop-down to update the text property of a text box or label.  However, when I select an item from the drop-down the text box or label is not updated.  However, if I add a button to my page and click it, the text box or label is correctly updated.  So, I know that my code is working but the autopostback is not.  Any help would be greatly appreciated.  I am under a time crunch.  Thanks in advance.

David

0
Comment
Question by:davidbristow
  • 6
  • 6
14 Comments
 
LVL 13

Expert Comment

by:PraxisWeb
ID: 17052003
Would need to see your code, but your Page_Load event may be overriding your OnSelectedIndexChange event
0
 

Author Comment

by:davidbristow
ID: 17052155
Thank you for responding.  As you can see from below I have no code in my page_load.   know that the code and postback are working because when I click a button it works correctly.  It is just the autopostback.  Is there a way to simulate a button being clicked or to force a postback through VB code?  Perhaps this would work.  

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub
0
 
LVL 13

Expert Comment

by:PraxisWeb
ID: 17052271
What does the open asp:DropDownList code look like?
0
 

Author Comment

by:davidbristow
ID: 17052343
Simple code.

Protected Sub statusDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles statusDropDownList.SelectedIndexChanged
        statusLabel.Text = statusDropDownList.SelectedValue
    End Sub

Again, the code works correctly when I click a button.  However, the postback is not happening automatically when a value is selected from the drop-down.  I have also experimented with the autopostback on a text box, checkbox, etc. and all are not automatically posting back.  Thanks again for your help.

David
0
 
LVL 13

Expert Comment

by:PraxisWeb
ID: 17052452
What about in the .aspx page the actual xml markup, what does it look like?
0
 

Author Comment

by:davidbristow
ID: 17052541
Again, I am new to this so please forgive my ignorance.  In the .aspx page I see only references to asp.  Howeve, there are two references to xmlns.  Is there any correlation between xmlns and xml?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

In the .aspx.vb page I only see some simple vb code

Partial Class _Default
    Inherits System.Web.UI.Page


    Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Label1.Text = "~/" & TextBox1.Text & ".htm"
        HyperLink1.NavigateUrl = "~/" & TextBox1.Text & ".htm"
    End Sub

    Protected Sub statusDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles statusDropDownList.SelectedIndexChanged
        statusLabel.Text = statusDropDownList.SelectedValue
    End Sub
End Class

Finally, in the web.config file I see the following xml

<?xml version="1.0"?>
<!--
    Note: As an alternative to hand editing this file you can use the
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in
    machine.config.comments usually located in
    \Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
      <appSettings/>
      <connectionStrings/>
      <system.web>
            <!--
            Set compilation debug="true" to insert debugging
            symbols into the compiled page. Because this
            affects performance, set this value to true only
            during development.

            Visual Basic options:
            Set strict="true" to disallow all data type conversions
            where data loss can occur.
            Set explicit="true" to force declaration of all variables.
        -->
            <compilation debug="true" strict="false" explicit="true"/>
            <pages>
                  <namespaces>
                        <clear/>
                        <add namespace="System"/>
                        <add namespace="System.Collections"/>
                        <add namespace="System.Collections.Specialized"/>
                        <add namespace="System.Configuration"/>
                        <add namespace="System.Text"/>
                        <add namespace="System.Text.RegularExpressions"/>
                        <add namespace="System.Web"/>
                        <add namespace="System.Web.Caching"/>
                        <add namespace="System.Web.SessionState"/>
                        <add namespace="System.Web.Security"/>
                        <add namespace="System.Web.Profile"/>
                        <add namespace="System.Web.UI"/>
                        <add namespace="System.Web.UI.WebControls"/>
                        <add namespace="System.Web.UI.WebControls.WebParts"/>
                        <add namespace="System.Web.UI.HtmlControls"/>
                  </namespaces>
            </pages>
            <!--
            The <authentication> section enables configuration
            of the security authentication mode used by
            ASP.NET to identify an incoming user.
        -->
            <authentication mode="Windows"/>
            <!--
            The <customErrors> section enables configuration
            of what to do if/when an unhandled error occurs
            during the execution of a request. Specifically,
            it enables developers to configure html error pages
            to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->
      </system.web>
</configuration>





0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:davidbristow
ID: 17053303
Here's another way to do this. Still worth 500 points for your time and efforts (much appreciated).

Enter File_1 into TextBox1
Click Button1
Write the on_click section of button_1 to open a _blank web page with the string "~/" & TextBox1.text & ".htm"

So, this is my question:  Do you know how to open a _blank web page for the on_click event of a button?  I am using VB.  Is there another way that I should be doing this?

Again, any help would be appreciated.

David
0
 
LVL 13

Expert Comment

by:PraxisWeb
ID: 17053433
I guess the next question from me would be what is it that you want to ultimately accomplish?

We can make a drop-down post information back to either itself or a new page, and we should be able to get your autopostback working as well...

as far as the above code goes I need to see all the stuff that comes after the:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
0
 
LVL 13

Expert Comment

by:PraxisWeb
ID: 17053438
I am heading back to the house now, so it may be a while before I can respond... but I haven't forgotten ya
0
 

Author Comment

by:davidbristow
ID: 17054054
I have a text box called "partnoTextBox".  I barcode scan a part number into this field.  Example:  "cat347" .  I want to press Enter or click a link or button and open a web page "~/Work_Instructions/[scanned part number].htm" .  In this example I would open "~/Work_Instructions/cat347.htm"

The closest that I have come to doing this is the following:

1.  Scan partno
2.  press Enter (causing a postback)
3.  I run the following code to update the navigateURL property for a hyperlink

 Protected Sub partnoTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles partnoTextBox.TextChanged
        openpartnoHyperlink.NavigateUrl = "~/Work_Instructions/" & partnoTextBox.Text & ".htm"
    End Sub

4.  I click the hyperlink and it works

However, I need to streamline the process to either (or both)

  1.  Scan the partno and press enter
  2.  Scan the partno and click a button or hyperlink

As you can see, the closest that I have gotten to this is

  2.  Scan the partno, press Enter, then click a hyperlink

This is for a production plant and so they are picky about extra keystrokes or mouse clicks.  I haven't had my solution of the three-step process accepted.

My automatic postback with a drop-down still isn't working but I can address this in another submission.  The above is the priority.

Sorry about any confusion up until now.  I am new to ExpertsExchange and see that I have to ask questions that get right to the point with relevant code.

David
0
 
LVL 13

Accepted Solution

by:
PraxisWeb earned 500 total points
ID: 17058364
Ok well there are a couple things we can do here... the first thing would be too look into whether or not your scanner can append an Enter to the end of its data... most can.   That way you can skip manually pressing the enter key.

Next, instead of creating a hyperlink you could do a Server.Transfer() or a Response.Redirect() and automatically send them to the new page, something like

Protected Sub partnoTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles partnoTextBox.TextChanged
        Server.Transfer(String.Format("~/Work_Instructions/{0}.htm",partnoTextBox.Text))
End Sub
0
 

Author Comment

by:davidbristow
ID: 17060640
Wow!!!!!!  Thank you so much!  The code works perfectly.  I was wondering how to open a new web page with VB code.  I am so grateful.

I have two more questions related to the above code.  If you want, I can open a new question so that you can get further points as I am so grateful for your help thus far.  Just let me know.

1.  How would I modify the above code to open the page in a new window?

2.  If the scanned work instruction file can't be found, how do I intelligently do error handling.  I want to let the user know that the work instruction file is not available, blank the partnoTextBox field, then bring the cursor back to this field and let them try again.

David
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now