Showing posts with label causing. Show all posts
Showing posts with label causing. Show all posts

Monday, March 26, 2012

Calling __doPostBack causing full postback :-(

Ok, if I capture an event on the client, for example, a click event on a textbox that is inside an update panel, and in that event I call __doPostBack I get a full postback.

However, if I add a button and call it's click event, I get the partial page update I want. So I guess the question is how to invoke a partial page update via script?

Thanks ... Ed

Make sure the appropriate trigger has been set up for the UpdatePanel. You can also set the TextBox to have AutoPostBack="true" which will add a __doPostBack to the onchange event handler.

Of course if you absolutely need to trigger a button click from JavaScript you can do something similar to this:

<

htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
<scriptlanguage=javascript>
function SemiHacky(){
__doPostBack('Button1','');
}
</script>
</head>
<body>
<formid="form1"runat="server">
<asp:ScriptManagerID="ScriptManager1"runat="server">
</asp:ScriptManager>
<asp:UpdatePanelID="UpdatePanel1"runat="server">
<Triggers><asp:AsyncPostBackTriggerControlID=Button1EventName="Click"/></Triggers>
<ContentTemplate>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:ButtonID="Button1"runat="server"Text="Button"/>
<br/><br/>
<ahref="javascript:SemiHacky();">Click here</a> to execute some JavaScript and submit the Button1 button via JavaScript.
</form>
</body>
</html>

The code behind is just setting the Label text to the current time so you can see the PostBack occur:

Label1.Text =DateTime.Now.ToString();

Cheers,
Al


Hi,

I did exactly as you suggested, but to no avail.

I am trying to launch a modal dialog and I have tried the following variations, some of which seem to work correctly, except that once the modal dialog is display and I try to dismiss it via a server

side mydlg.close() I get an error stating "The control 'dlgDivTasks' already has a data item registered."

These are the individual calls that I have tried. I should point out that if I just to a plain __doPostBack("","") I get a full postback and no error when I try to dismiss the dialog.

_doPostBack('Button1','');
__doPostBack("","");
Sys.WebForms.PageRequestManager.getInstance()._doPostBack("","");
document.forms[0].ctl00_ContentPlaceHolderContent_Button1.click();
$find("DlgTasksBehavior").show();

Thanks ... Ed


Hi Ed,

Have you had any luck using the OnOkScript property of the ModalPupupExtender? One way that I use the modal popup is I have an Ok and Cancel button but they may be named differently based on user actions (ie. Cancel may be labelled as Close). I then use the OnOkScript to execute some client JavaScript which then uses a web service to pass the data back to the server for some processing.

OkControlID="btnOk"OnOkScript="modalOkScript()"CancelControlID="btnCancel"

function

modalOkScript(){
//TODO: Add some web service call to take care of my data processing requirements
}

When the Web Service completes, the onSuccess JavaScript function for the webservice in my OnOkScript function changes the 'Cancel' button text to 'Close.

function

onSuccessModalOkScript(result){
$get('btnOk').disabled =true;
$get('btnCancel').value ='Close';
}

Then it's finished and the Modal closes via client side when the user is ready.

Al


Looks like my copy / paste made the JavaScript functions look odd.

Hi, thanks for the reply.

Wouldn't what you suggest be kinda limiting? I wouldn't have access to the various data and controls on the page unless I passed a mountain of parameters the the service call. Seems to me I should just be able to do an async update via the update panel so I can use my server side code to get the job done.

The thing that is a mystery to me is why it is doing a full post back in the first place.I have everything working perfectly it's just the damned blink!

Thanks ... Ed


I have just had a similar situation myself whereby a full postback was occuring whenever I called __doPostBack. Trick is that you have to specifiy the actual client ID in the EventTarget parameter

i.e. _doPostBack('', ''); will NOT work where as _doPostBack('ctl00_textBox1', ''); WILL work. Obviously thats just an example so replace ctl00_textBox1 with your actual clientID value

So my code became:

textJobRef.Attributes.Add("onkeyup","javascript:setTimeout('__doPostBack(\'" + textJobRef.ClientID +"\', \'\')', 0)")

I dont think the timeout is required, but .NET does it so it must be for a reason! :)

Wednesday, March 21, 2012

CalendarExtender, ValidatorCallout, or FilteredTextboxExtender Causing Error in Partial Po

Hello everyone,

I really enjoy working with the Controls Tookit. The ValidatorCallout is especially nice to use. I'm trying to use a drop-down list to cause a partial postback in an updatepanel. When the ddl selectionchanges, it is supposed to pull database information and then populate some textfields. These textfields have been wrapped in sometimes all three of the extenders listed above. When I change the selection on the ddl, I get a Javascript error:

Line: 5909 Char: 12 Sys.ArgumentUndefinedException: value cannot be undefined. Parameter name: id.

I know this is in one of the javascript files that get attached to my code when it gets built. I'm trying to figure out what's the root cause. Do you think the page is trying to validate the empty textfields? The validatorcallouts are not firing, if that is the case. I've attached my aspx code. Let me know if the code-behind would be useful as well.

Thanks for any help you can provide.

<asp:ScriptManager runat="server" ID="smModify" /> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <table> <tr> <td colspan="3" style="font-size: x-large"><b>Common Fields</b></td> </tr> <tr> <td class="spacer"> </td> <td align="right">Branch Number:</td> <td> <asp:DropDownList ID="ddlSharedBranches" runat="server" AutoPostBack="True"> </asp:DropDownList><%--<asp:TextBox ID="txtBranchNumber" runat="server" MaxLength="5"></asp:TextBox> <ajax:FilteredTextBoxExtender ID="ftxteBranchNumber" runat="server" TargetControlID="txtBranchNumber" FilterType="Numbers"> </ajax:FilteredTextBoxExtender> <asp:RequiredFieldValidator ID="rfvBranchNumber" runat="server" display="none" ErrorMessage="Please enter data in the form #####." ControlToValidate="txtBranchNumber"></asp:RequiredFieldValidator> <ajax:ValidatorCalloutExtender ID="vceBranchNumber" runat="server" TargetControlID="rfvBranchNumber" HighlightCssClass="validateCallout"> </ajax:ValidatorCalloutExtender>--%> </td> </tr> <tr> <td class="spacer"> </td> <td align="right">Branch Name:</td> <td> <asp:TextBox ID="txtBranchName" runat="server" MaxLength="30"></asp:TextBox> <asp:RequiredFieldValidator ID="rfvBranchName" runat="server" display="none" ErrorMessage="Please enter the Branch's Name here." ControlToValidate="txtBranchName"></asp:RequiredFieldValidator> <ajax:ValidatorCalloutExtender ID="vceBranchName" runat="server" TargetControlID="rfvBranchName" HighlightCssClass="validateCallout"> </ajax:ValidatorCalloutExtender> </td> </tr> <tr> <td class="spacer"> </td> <td align="right">Bank:</td> <td> <asp:DropDownList ID="ddlBank" runat="server"> <asp:ListItem Text="Carolina First" Value="1"></asp:ListItem> <asp:ListItem Text="Mercantile Bank" Value="6"></asp:ListItem> </asp:DropDownList> </td> </tr> <tr> <td colspan="3"> <asp:CheckBox ID="cbTOSS" runat="server" AutoPostBack="true" />Modify TOSS Fields </td> </tr> <tr> <td colspan="3"> <asp:Panel ID="pnlTOSS" runat="server"> <table> <tr> <td colspan="3"><b>TOSS Specific Fields</b></td> </tr> <tr> <td class="spacer"> </td> <td align="right">Region:</td> <td> <asp:DropDownList ID="ddlAddBranchTOSSRegion" runat="server"> </asp:DropDownList> </td> </tr> <tr> <td class="spacer"> </td> <td align="right">Number of Tellers:</td> <td> <asp:TextBox ID="txtAddBranchTOSSNumTellers" runat="server" MaxLength="2"></asp:TextBox> <ajax:FilteredTextBoxExtender ID="ftxteAddBranchTOSSNumTellers" runat="server" TargetControlID="txtAddBranchTOSSNumTellers" FilterType="Numbers"> </ajax:FilteredTextBoxExtender> <asp:RequiredFieldValidator ID="rfvAddBranchTOSSNumTellers" runat="server" display="none" ErrorMessage="This field is required." ControlToValidate="txtAddBranchTOSSNumTellers"> </asp:RequiredFieldValidator> <ajax:ValidatorCalloutExtender ID="vceAddBranchTOSSNumTellers" runat="server" TargetControlID="rfvAddBranchTOSSNumTellers" HighlightCssClass="validateCallout"> </ajax:ValidatorCalloutExtender> </td> </tr> <tr> <td class="spacer"> </td> <td align="right">Sales FTE:</td> <td> <asp:TextBox ID="txtAddBranchTOSSSalesFTE" runat="server" MaxLength="7"></asp:TextBox> <ajax:FilteredTextBoxExtender ID="ftxteAddBranchTOSSSalesFTE" runat="server" TargetControlID="txtAddBranchTOSSSalesFTE" FilterType="Custom" ValidChars=".0123456789"> </ajax:FilteredTextBoxExtender> <asp:RequiredFieldValidator ID="rfvAddBranchTOSSSalesFTE" runat="server" display="none" ErrorMessage="This field is required." ControlToValidate="txtAddBranchTOSSSalesFTE"> </asp:RequiredFieldValidator> <ajax:ValidatorCalloutExtender ID="vceAddBranchTOSSSalesFTE" runat="server" TargetControlID="rfvAddBranchTOSSSalesFTE" HighlightCssClass="validateCallout"> </ajax:ValidatorCalloutExtender> </td> </tr> <tr> <td class="spacer"> </td> <td align="right">Effective Date:</td> <td> <asp:TextBox ID="txtAddBranchTOSSEffectiveDate" runat="server" MaxLength="10"> </asp:TextBox><asp:Image ID="imgCalendar" runat="server" ImageUrl="images/cldrimg.png" /> <ajax:FilteredTextBoxExtender ID="ftxteAddBranchTOSSEffectiveDate" runat="server" TargetControlID="txtAddBranchTOSSEffectiveDate" FilterType="custom" ValidChars="0123456789//"> </ajax:FilteredTextBoxExtender> <ajax:CalendarExtender ID="cldreAddBranchTOSSEffectiveDate" runat="server" TargetControlID="txtAddBranchTOSSEffectiveDate" Animated="true" PopupButtonID="imgCalendar"> </ajax:CalendarExtender> <asp:RequiredFieldValidator ID="rfvAddBranchTOSSEffectiveDate" runat="server" display="none" ErrorMessage="This field is required." ControlToValidate="txtAddBranchTOSSEffectiveDate"> </asp:RequiredFieldValidator> <ajax:ValidatorCalloutExtender ID="vceAddBranchTOSSEffectiveDate" runat="server" TargetControlID="rfvAddBranchTOSSEffectiveDate" HighlightCssClass="validateCallout"> </ajax:ValidatorCalloutExtender> </td> </tr> </table> </asp:Panel> </td> </tr> <tr> <td colspan="3"> <asp:CheckBox ID="cbTSFGu" runat="server" AutoPostBack="true" />Modify TSFGu Fields </td> </tr> <tr> <td colspan="3"> <asp:Panel ID="pnlTSFGu" runat="server"> <table> <tr> <td colspan="3"><b>TSFGu Specific Fields</b></td> </tr> <tr> <td class="spacer"> </td> <td align="right">Region:</td> <td> <asp:DropDownList ID="ddlAddBranchTSFGuRegion" runat="server"> </asp:DropDownList> </td> </tr> </table> </asp:Panel> </td> </tr> </table>


I was able to narrow it down to the ValidatorCallout causing the error.

I'm able to run the ddl one time to fill in the fields. It results in the error described above, but the fields fill in. If I try to select another branch from the dropdown list above, the error keeps the postback from going. So it's a one-shot deal, otherwise you have to reload.

Removing the updatepanel removes all of the errors and it works perfectly, but the tell-tale page flicker is back.