Showing posts with label link. Show all posts
Showing posts with label link. Show all posts

Wednesday, March 28, 2012

How do I send email using ajax modal popup extender

I have a panel that sends an email message. I wish to use an ajax modal popup extender to display this panel when a user clicks a "Contact Us" link button. I get an error message when I try to run the application. My code follows.Thank you for any suggestions.

<body>
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" />
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
TargetControlID ="ContactUsLinkButton"
PopupControlID ="EmailPopupPanel"
OkControlID="OKButton"
CancelControlID="CancelButton"
DropShadow="true"
BackgroundCssClass ="modalBackground" />
<asp:LinkButton ID="ContactUsLinkButton" runat="server">Contact Us</asp:LinkButton>


<div >
<asp:Panel ID="EmailPopupPanel" runat="server" CssClass ="popupEmail" Width="325px" Style="display: none" >
<asp:Label ID="TitleLabel" runat="server" BackColor="#FFFFC0"
Font-Bold="True" Font-Size="Medium" ForeColor="SteelBlue" Text="Contact D`Stroke Tennis"
Width="300px"></asp:Label>
<br />
<asp:Label ID="InfoLabel" runat="server" Font-Bold="True" Font-Size="Medium" ForeColor="Red"></asp:Label>
<br />
<br />
<asp:Button ID="OKButton" runat="server" BackColor="#FFFFC0" Font-Bold="True" ForeColor="DarkRed"
Text="OK" Visible="False" /><br />
<span style="color: #990000"><strong><asp:Label ID="FromLabel" runat="server" Text="From:"></asp:Label></strong> </span>
<asp:TextBox ID="FromTextBox" runat="server" Width="250px" ForeColor="DarkRed"></asp:TextBox>
<br />
<br />
<asp:Label ID="ToLabel" runat="server" Text="To: admin@dotnet.itags.org.dstroketennis.com" Width="300px" BackColor="#FFFFC0" Font-Bold="True" ForeColor="DarkRed"></asp:Label>
<br />
<br />
<span style="color: #990000"><strong><asp:Label ID="SubjectLabel" runat="server"
Text="Subject:"></asp:Label></strong></span>
<asp:TextBox ID="SubjectTextBox" runat="server" Width="240px"></asp:TextBox><br />
<br />
<span style="color: #990000"><strong>
<asp:Label ID="MessageLabel" runat="server"
Text="Message:"></asp:Label></strong></span><br />
<asp:TextBox ID="MessageTextBox" runat="server" Height="150px" TextMode="MultiLine"
Width="300px" ForeColor="DarkRed"></asp:TextBox><br />
<asp:Button ID="SendEmailButton" runat="server" BackColor="#FFFFC0" BorderColor="DarkRed"
BorderStyle="Solid" Font-Bold="True" ForeColor="DarkRed" Text="Send Email" Width="173px" />
<br />
<asp:Button ID="CancelButton" runat="server" BackColor="#FFFFC0" BorderColor="DarkRed"
BorderStyle="Solid" Font-Bold="True" ForeColor="SteelBlue" Text="Cancel Email" Width="173px" /></asp:Panel>
</div>
</form>
</body>

Tags:ajax, ie 7, Microsoft JScript runtime error: Sys.ArgumentNullException: Value cannot be null. Parameter name: element

When do you get the Sys.ArgumentNullException error? Also, try getting rid of the Style="display: none" on the Panel...

-Damien


I get the error when the page loads.


I Got rid of the Style "display : none" and I get the same error on page load.


See if this related post helps:http://forums.asp.net/p/1107533/1700376.aspx

-Damien


I also ran across this:http://www.spthorn.com/blog.php?post=28&PHPSESSID=c42ace58bb0f0d24ab3d9d2eef948c4a

-Damien


Thanks Damien. The asp buttons weren't plugged into anything I am guessing. My new challenge with this now is to have the email send, and display a message that the send was a success before leaving modal state.

At least this one issue is handled.

Monday, March 26, 2012

How do I dynamically create updatepanel and then contenttemplate linkbutton and triggers a

I need to be able to create multiple updatepanels which have a link button in them. I have no idea how many updatepanels I'm going to have which have link buttons as the data coming back is from a database. Right now I'm taking the data from a database and putting that into a datalist.

It all works great until I wanted to add a updatepanel to it; then it said the updatepanel cannot be used in that context. So, if it cannot be as simple as what I tried below, how do I dynamically create an updatepanel for each row of data returned from the database?

Each row in the database has a unique ID so the ID of the linkbutton and the asyncpostbacktrigger controlid could be assigned that unique ID.

This works fine without adding updatepanel:
<asp:ScriptManager ID="ajaxClientComponentMgr" EnablePartialRendering="true" runat="server">
<Services>
<asp:ServiceReference Path="~/AjaxWebService.asmx" InlineScript="true" />
</Services>
<Scripts>
<asp:ScriptReference Path="~/Javascript/ajaxJScript.js" />
</Scripts>
</asp:ScriptManager>

<asp:DataList ID="DataSource_Stories_Display" runat="server">
<ItemTemplate>
<asp:Table CssClass="stories_table_block" runat="server">
<asp:TableRow runat="server">
<asp:TableCell CssClass="stories_right_content" runat="server">
<span class="stories_content_header"><%#DataBinder.Eval(Container.DataItem, "Title Name:")%></span><br />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</ItemTemplate>
</asp:DataList>

This complains of being "not in this context" after adding updatepanel:
(Note: unique_id_for_this_link added just to show that each iteration would have a unique number at that location)

<asp:ScriptManager ID="ajaxClientComponentMgr" EnablePartialRendering="true" runat="server">
<Services>
<asp:ServiceReference Path="~/AjaxWebService.asmx" InlineScript="true" />
</Services>
<Scripts>
<asp:ScriptReference Path="~/Javascript/ajaxJScript.js" />
</Scripts>
</asp:ScriptManager>

<asp:DataList ID="DataSource_Stories_Display" runat="server">
<ItemTemplate>
<asp:Table CssClass="stories_table_block" runat="server">
<asp:TableRow runat="server">
<asp:TableCell CssClass="stories_right_content" runat="server">
<span class="stories_content_header"><%#DataBinder.Eval(Container.DataItem, "Title Name:")%></span><br />

<asp:UpdatePanel ID="something_unique_id_for_this_panel" ChildrenAsTriggers="False" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:LinkButton ID="unique_id_for_this_link" OnClientClick="paneDataRequest();return false;" CssClass="story_link" runat="server">Click Me</asp:LinkButton>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="unique_id_for_this_link" />
</Triggers>
</asp:UpdatePanel>

</asp:TableCell>
</asp:TableRow>
</asp:Table>
</ItemTemplate>
</asp:DataList>

UPDATE: Okay...Swapping where UpdatePanel was located fixed part of the issue.

UpdatePanel, if it is outside of Datalist will work as follows:

<asp:UpdatePanel ChildrenAsTriggers="False" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:DataList ID="DataSource_Stories_Display" runat="server">
<ItemTemplate>
<asp:Table CssClass="stories_table_block" runat="server">
<asp:TableRow runat="server">
<asp:TableCell CssClass="stories_right_content" runat="server">
<span class="stories_content_header"><%#DataBinder.Eval(Container.DataItem, "Title Name:")%></span><br />
<asp:LinkButton OnClientClick="paneDataRequest();return false;" CssClass="story_link" runat="server">Click Me</asp:LinkButton>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
<Triggers>
</Triggers>
</asp:UpdatePanel>

New problem discovered!

If I try to assign an ID to the asp:LinkButton (a unique value for each row of database data) I just end up getting all types of errors:

<asp:LinkButton id="some_unique_id" OnClientClick="paneDataRequest();return false;" CssClass="story_link" runat="server">Click Me</asp:LinkButton>

If the ID is omitted, it works fine...not what I'm after.

Next Question:

How do I assign a unique ID number to LinkButton? If I cannot assign it, how can I determine the IDs which are assigned to it so that I can build the <triggers></triggers> part of the updatepanel control?


UPDATE 2:

Visual Studio .Net Beta 2, using the scenario above from second post, does not auto-generate IDs (when you view source of the generated page) for:

<asp:LinkButtonOnClientClick="paneDataRequest();return false;"CssClass="story_link"runat="server"></asp:LinkButton>

Visual Studio .Net Beta 2, using the scenario above from second post, does auto-generate name values (although not IDs) for buttons such as:

<asp:ButtonOnClientClick="paneDataRequest();return false;"Text="default"runat="server"></asp:Button>