Jump to content

Stumped at a Masterpage + contentpage + User Control + button click

- - - - -

  • Please log in to reply
5 replies to this topic

#1
ManyTimes

ManyTimes

    Newbie

  • Members
  • PipPip
  • 14 posts
Hello guys!

My problem:
A master page with a contentplaceholder
A contentpage with a button and a updatepanel with a placeholder "PH" in it, which is loaded into the contentplaceholder in the master page.
A WebUserControl with a button and a label, which is loaded into the contentpage's "PH" when the contentpage button is clicked.
Clicking the button in the WebUserControl should then update the label with the correct datetime.now(), which do not happen on the first button click! But on all the rest, it works just fine... So, how can I make it work on the first button click?

My WebUserControl (ASPX file):
<asp:Panel runat="server" ID="tt">
    <asp:Button Text="Update" runat="server" CssClass="btn" ID="btnUpdate" 
    onclick="btnUpdate_Click" />
    <br />
    <asp:Label runat="server" ID="lbl1">Lbl1 :</asp:Label>
    <br />
    <asp:Label runat="server" ID="lbl2">Lbl2: </asp:Label>
</asp:Panel>
My WebUserControl (CodeBehind, C#)
        protected void Page_Load(object sender, EventArgs e)
        {
            lbl1.Text = "Loaded: " + DateTime.Now.ToLongTimeString();
            [COLOR=Red]btnUpdate.Click += new EventHandler(btnUpdate_Click);[/COLOR]
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            lbl1.Text = "Button event: " + DateTime.Now.ToLongTimeString();
            upBtn.Update();
            lbl2.Text = "Updated";
        }
Suggestions are more than welcome! Should be fairly simple... (Yes, have google'd a lot, still am!) :)

The function "btnUpdate_click" fires always, except on the first click, seems like the page needs to do a postback before it can use the function?

I've tried putting the "new Eventhandler" in everywhere, "Page_PreRender", "Page_Init"... Tried not having it...

#2
gokuajmes

gokuajmes

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 518 posts
actually this is a Bug with Ajax control ,if you try this under the Internet Explorer works fine but FF click 2ice to make it work.

try with the code below & pingBack

ASPx page
 <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:Label ID="lblMsg" runat="server"></asp:Label>
        <asp:Button ID="btnPostback" runat="server" Text="GetTime" OnClick="btnPostback_Click" />
        </ContentTemplate>
    </asp:UpdatePanel>

CodeBehind
protected void btnPostback_Click(object sender, EventArgs e)
    {
        lblMsg.Text = "Loaded :" + DateTime.Now.ToLongTimeString();
    }

Edited by gokuajmes, 12 May 2010 - 01:04 AM.
included code for reference


#3
ManyTimes

ManyTimes

    Newbie

  • Members
  • PipPip
  • 14 posts
Thanks for the response! :)

Well, it is a bug? oh...hmm, sure of this?

Not even going to try your code, because, well, I ain't newbie?... And that works, but the problem lies when I add WebUserControls, it goes down deep into the "architecture":
masterpage>contentpage>behindcode>WebUserControl>FinalWebUserControl>ButtonClick
And at this very button, after so many "levels down the web"... I have to click twice in both IE and FF.
Even with and without adding ScriptManager.Register...(btn)... tried for two days... with over a hundred different combinations of, everything... oh well.

I think I'll use my old method, cause I have a solution (Code everything in C#), used it two years ago, but was digging for a simpler solution.

#4
gokuajmes

gokuajmes

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 518 posts

ManyTimes said:

Well, it is a bug? oh...hmm, sure of this?
off course i am.Not with the current Release though

ManyTimes said:

Not even going to try your code, because, well, I ain't newbie?
Glad you are not!!^^

ManyTimes said:

I think I'll use my old method, cause I have a solution (Code everything in C#), used it two years ago, but was digging for a simpler solution.
Happy you had a solution at start . Now i can go have my Coffee

#5
pengling

pengling

    Newbie

  • Members
  • Pip
  • 2 posts
Suggestions are more than welcome:P

#6
ManyTimes

ManyTimes

    Newbie

  • Members
  • PipPip
  • 14 posts
pengling: What is it!?!? :)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users