Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...PostBack same page, retrieve variable in On_LoadPostBack same page, retrieve variable in On_Load
Previous
 
Next
New Post
1/26/2009 7:47 PM
 

I'm brand spanking new to DNN development. In fact, if anyone wants to throw links at me on documents that layout DNN's framework or any other great literature that will get me up to speed on developing modules for DNN, go ahead. But, here's the reason for my post...

Firstly, I'm working in C#.

I'm trying to do a PostBack to the same page, but trigger that PostBack by Javascript function (which is called by a Flash function, because apparently there's not a way to run a C# function from Flash?). Anyway, for this application, I only need to pass one hidden value. Then compare that value within an IsPostBack check of the Page_Load procedure to display an object and/or run a LINQ insert.

I've been working on this for a while, and I can't seem to get it to work...

1. I don't know how to trigger the PostBack with Javascript.

2. I'm not sure how to consume the passed value in the code behind.

3. I'm not sure that the page isn't just refreshing.

Since all that relies on each other, it makes it about impossible to trouble shoot... any help would be MUCH appreciated.

 

 

 
New Post
1/28/2009 1:38 AM
 

Maybe this is completely a newb question and it's not worthy of an answer, or maybe I'm not clear on what I was trying to do.

I'm trying to PostBack hidden form data from within a DNN Module, triggered by Javascript, and then consume that data in the Page_Load function.

My page form:

<form runat="server" id="watchform" visible="false" method="get">
<input runat="server" type="hidden" id="watchKey" value="true" />
<input runat="server" id="watchformSubmit" type="button" value="submit" />
</form>

My

<script type="text/javascript">
function runPostback(){
    document.getElementById.watchformSubmit.click();
}
</script>

Code Behind:

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var feedback = Request.QueryString["watchKey"];
                Label1.Text = "Postback: " + feedback;
            }

        }

 

As far as I can tell my form and Javascript are working, but I'm not exactly sure how to define a varible with the returned form data. I've tried GetCallbackEventReference but get errors. So, how do I get the watchKey value from the form?

 
New Post
1/28/2009 1:27 PM
 

As a postback you wouldn't actually be grabbing it from the QueryString collection.  In fact, because you created it as a server object (runat=server) you can merely access it directly via code as watchKey.Value.  So something more like:

protected void Page_Load(object sender, EventArgs e)
{
  // note, not !IsPostBack because that means on the initial load of the page
  if (IsPostBack)
  {
    // TODO: do something with your value
    string feedback = watchKey.Value;
    // optional way to access value: Request.form["watchKey"]
  }
}

EDIT: I noticed that you have this in a "subform".  ASP.NET, in general and without hacks, only supports a single form tag per page.  DotNetNuke will automatically insert the form tag (from default.aspx) and then injects your skin and modules inside that form.  Since your form is marked as runat=server and visible=false I think that is why no error is being thrown.  Just pull that extra form out and if you want to logically group those components slap them into a div or asp:Panel.


-- Jon Seeley
DotNetNuke Modules
Custom DotNetNuke and .NET Development
http://www.seeleyware.com
 
New Post
1/29/2009 4:50 AM
 

I tried that but it throws all kinds of errors...

I really don't even need to pass a value or a string with the PostBack. I really just need to trigger a C#/.NET function with Javascript. Below is what I have, and I don't understand why it's not working.

 

JS:

<script type="text/javascript">

function writeStatus(){
    // End!"); 
    document.getElementById("submitStatusBtn").click();
}

</script>

ASP:

<asp:Button ID="submitStatusBtn" runat="server" onclick="Button1_Click" Text="Button" />

CB:

protected void Button1_Click(object sender, EventArgs e)
        {
            RunMyFunction();
        }

 

Is it not possible to "document.getElementById("submitStatusBtn").click();"?

I've read about 4 different ways to do this, but none seem to work with DNN. There's got to be a way to do this... Call C# function with Javascript, either by callback or postback. But, I can't figure it out...

 

 
New Post
1/29/2009 9:22 AM
 

It *is* possible to get the element by id as such however you need to use the CLIENTID of the component, not the "ID".  The thing here is that because of it's dynamic nature, ASP.NET allows you to arbitrarily include controls as children of other controls and assign a name/ID that you can relate to.  However, what if another control on the page already has the same name?  This is where the "naming container" feature of ASP.NET comes in.  Lets say I have a DataList named "listEmployees" and each row in the list has a template with a textbox, image, and checkbox which I name "textName", "imgPhoto", and "chkActive" respectively.  Each row can't possibly name their control that in reality because we'd have naming conflicts so ASP.NET proceeds to help us out with that naming it something like listEmployees_ctl1_textName, listEmployees_ctl1_imgPhoto, listEmployees_ctl1_chkActive and so on.  You would use a listEmployees.Items[x].FindControl("textName") to retrieve a reference to that particular textbox for that particular employee record.

So to relate that to DNN and tie it all in.  DNN is composed of UserControls which, by their very nature, function as Naming Containers.  If you were to view source on a DNN page you'd see things named like "dnn_ctr450_dnnTITLE_lblTitle" (which is the TITLE element for module #450 on my page).  Pretty nasty and not easy to work with.  However, enter ClientID.  *ALL* controls have a property for ClientID which is their generated naming container + given ID.  Lets apply that to your sample now (using server side script to inject the ClientID into your clientside script):

<script type="text/javascript">

function writeStatus(){
    // End!"); 
    document.getElementById("<%= submitStatusBtn.ClientID %>").click();
}

</script>

As you can see I injected the clientID of your server-side control into your clientside script.  For more information about this I googled and came up with this page by one James Gregory.  His method is in no way the standard but one that I think is pretty nice.  I tend to just inject some javascript during OnPreRender that stores the namespace into a javascript variable (so I'd output to the page from the module itself something to the effect of: var _ns = this.ClientID and then my javascript would say document.getElementById(_ns + "submitStatusBtn").  There are plenty of ways to accomplish it, that's just one I've chosen to use.

Hopefully that helps you on the javascript side?


-- Jon Seeley
DotNetNuke Modules
Custom DotNetNuke and .NET Development
http://www.seeleyware.com
 
Previous
 
Next
HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...PostBack same page, retrieve variable in On_LoadPostBack same page, retrieve variable in On_Load


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out