364,033 Members | 4774 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

GetPostBackEventReference Problem

JROY
P: 1
My page has 2 usercontrols dynamically created. Both implement IPostBackEventHandler. I created the RaisePostBackEvent method. In the parent page, I used GetPostBackEventReference. The first time, it works fine. In the next few clicks need to click 2 times to enter the RaisePostBackEvent. Anyone have any tips? The following code:

Parent Page
Expand|Select|Wrap|Line Numbers
  1. Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
  2.         CarregaUserControl()
  3. End Sub
  4.  
  5. Private Sub CarregaUserControl()
  6.         divControls.Controls.Clear()
  7.  
  8.         Select Case p_Step
  9.             Case WizardStep.PersonalData
  10.                 uc_usrDadosPessoais = CType(LoadControl("~/UserControl/User.ascx"), UserControl_User)
  11.                 divControls.Controls.Add(uc_usrDadosPessoais)
  12.  
  13.                 'lnkPersonalData.OnClientClick = "LinkClicado(1);" + Page.ClientScript.GetPostBackClientHyperlink(uc_usrDadosPessoais, "GERAREVENTO") + ";"
  14.                 'lnkCategory.OnClientClick = "LinkClicado(2);" + Page.ClientScript.GetPostBackClientHyperlink(uc_usrDadosPessoais, "GERAREVENTO") + ";"
  15.                 lnkPersonalData.Attributes.Add("onclick", "LinkClicado(1);" + Page.ClientScript.GetPostBackEventReference(uc_usrDadosPessoais, "GERAREVENTO") + ";document.forms[0].submit();")
  16.                 lnkCategory.Attributes.Add("onclick", "LinkClicado(2);" + Page.ClientScript.GetPostBackEventReference(uc_usrDadosPessoais, "GERAREVENTO") + ";document.forms[0].submit();")
  17.             Case WizardStep.Category
  18.                 uc_usrCategorias = CType(LoadControl("~/UserControl/UserCategory.ascx"), UserControl_UserCategory)
  19.                 divControls.Controls.Add(uc_usrCategorias)
  20.  
  21.                 lnkPersonalData.Attributes.Add("onclick", "LinkClicado(1);" + Page.ClientScript.GetPostBackEventReference(uc_usrCategorias, "GERAREVENTO") + ";document.forms[0].submit();")
  22.                 lnkCategory.Attributes.Add("onclick", "LinkClicado(2);" + Page.ClientScript.GetPostBackEventReference(uc_usrCategorias, "GERAREVENTO") + ";document.forms[0].submit();")
  23.         End Select
  24.     End Sub
  25.  
  26. Private Sub UCEvent(sender As Object, e As System.EventArgs) Handles uc_usrDadosPessoais.UCEvent, uc_usrCategorias.UCEvent
  27.         p_StepPrevious = p_Step
  28.         Select Case p_StepPrevious
  29.             Case WizardStep.PersonalData
  30.                 uc_usrDadosPessoais.SaveData()
  31.             Case WizardStep.Category
  32.                 uc_usrCategorias.SaveData()
  33.         End Select
  34.  
  35.         p_Step = Integer.Parse(hdnLinkClicado.Value)
  36.         CarregaUserControl()
  37.     End Sub
UserControl
Expand|Select|Wrap|Line Numbers
  1. Public Event UCEvent As EventHandler
  2. Public Overrides Sub RaisePostbackEvent(ByVal eventArgument As String)
  3.         Try
  4.             If eventArgument.Equals("GERAREVENTO") Then
  5.                 RaiseEvent UCEvent(Me, New EventArgs())
  6.             End If
  7.         Catch ex As Exception
  8.  
  9.         End Try
  10.     End Sub
Jan 20 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Help answer this question



Didn't find the answer to your ASP.NET question?