ASP.NET Weird Event Behaviour

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Xexon
    New Member
    • Dec 2007
    • 7

    ASP.NET Weird Event Behaviour

    Hey Guys,
    I'm experiencing some really odd behavior from the simple onclick event attached to one of my buttons.

    I have a user control, with three buttons Save, Edit and Create. They enable different asp.net controls and that's all working fine. However when I click my save button after I have edited some data, the new data is not loaded in with the onclick event of the save button.
    So to speak, it just reposts all the old values and stores these in my database again and the new values vanish.

    ASP code
    Code:
    <table width="300px" cellpadding="5"  cellspacing="0">
        <tr>
            <td>
                Navn:
            </td>
            <td>
                <asp:TextBox ID="txtSolutionName" runat="server" CssClass="TextBox200" />
            </td>
        </tr>
        <tr>
            <td width="100px">
                Kunde:
            </td>
            <td>
                <radC:RadComboBox          
                 ID="rcbCustomers"
                 runat="server"
                 Height="150px"
                 Width="200px"
                 MarkFirstMatch="true"
                 Skin="WindowsXP"
                 HighlightTemplatedItems="true"
                 Style="width:200px !important;">
                     <Items>
                         <radC:RadComboBoxItem Text="---Vælg---" Value="0"/>
                         <radC:RadComboBoxItem Text="Baltic Workforce" Value="1" />
                         <radC:RadComboBoxItem Text="AV Forlaget" Value="2" />
                         <radC:RadComboBoxItem Text="Finn Nygaard" Value="3" />
                         <radC:RadComboBoxItem Text="Merrild" Value="4" />
                         <radC:RadComboBoxItem Text="FC Fyn" Value="5" />
                         <radC:RadComboBoxItem Text="Mitsubishi" Value="6" />
                     </Items>
                </radC:RadComboBox>
            </td>
        </tr>
        <tr>
            <td width="100px">
                Skabelon:
            </td>
            <td>
                <radC:RadComboBox          
                 ID="rcbTemplates"
                 runat="server"
                 Height="150px"
                 Width="200px"
                 MarkFirstMatch="true"
                 Skin="WindowsXP"
                 HighlightTemplatedItems="true"
                 Style="width:200px !important;">
                     <Items>
                         <radC:RadComboBoxItem Text="---Vælg---" Value="0"/>
                         <radC:RadComboBoxItem Text="Totalløsning" Value="1"/>
                         <radC:RadComboBoxItem Text="Billedbank" Value="2"/>
                         <radC:RadComboBoxItem Text="Ekatalog" Value="3"/>
                         <radC:RadComboBoxItem Text="Ingen" Value="4"/>
                     </Items>
                </radC:RadComboBox>
            </td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td align="right">
                <asp:Button ID="btnCreateNewSolution" runat="server" Text="Opret" CssClass="Button" OnClick="btnCreateNewSolution_Click" />
                <asp:Button ID="btnEditSolution" runat="server" Text="Redigér" CssClass="Button" OnClick="btnEditSolution_Click" />
                <asp:Button ID="btnSaveSolution" runat="server" Text="Gem" CssClass="Button" OnClick="btnSaveSolution_Click" />
            </td>
        </tr>
    </table>
    Code Behind
    Code:
    public partial class ucCreateSolution : System.Web.UI.UserControl
        {
            
            protected void btnSaveSolution_Click(object sender, EventArgs e)
            {
                UpdateSolution(Convert.ToInt32(Request.QueryString["SolutionID"]));
                txtSolutionName.Enabled = false;
                rcbCustomers.Enabled = false;
                rcbTemplates.Enabled = false;
                btnCreateNewSolution.Visible = false;
                btnEditSolution.Visible = true;
                btnSaveSolution.Visible = false;
            }    
            private void UpdateSolution(int solutionID)
            {
                SolutionHandler.UpdateSolution(solutionID, txtSolutionName.Text, 0); //This is where the values are still the old ones, the txtSolutionName.Text takes the old value.
            }
        }
    Any help is greatly appreciated.

    Thanks in advance,
    --Michael
  • harshmaul
    Recognized Expert Contributor
    • Jul 2007
    • 490

    #2
    It is probably a dotnet post back problem.

    ensure that you're loading the data in to the boxes on page load and in an

    if(!IsPostBack)

    condition

    example...

    Code:
    if(!IsPostBack){
    txtTextBox1.Text="hello world";
    }

    Comment

    • ShahbazAshraf
      New Member
      • Mar 2008
      • 36

      #3
      1) May be your control is updating the value of "txtSolutionNam e" control
      2) In asp.net Page_Load event is fired on each post back and then the particular event is fire so in your scenario may be u have done some work which update the value of txtSolutionName .Text in Page_Load event.

      Comment

      Working...